Today, I cut the main project of the project from Swift3.3 to Swift4.1 with some changes and problems encountered. I would like to share them here, and hope that others will not step on the same pit.

Xcode9.3 (9E145) is the latest version of xcode

I use Cocoapods to manage third-party libraries. Although Carthage is good, some libraries don’t support it, so I use Cocoapods for my company projects.

Too much nonsense. Get into the business!

1. The code cutter swift4 of the main project is mainly used this time. Because some third-party libraries do not support it, some modifications need to be made in the Podfile as follows:



Manage third parties that have SWIFT4 and those that do not.

2. swift4 this time requires “@objc” before all #selector() methods.

Swift4 no longer supports the overloaded initialize () method

4. There is no support for overloaded methods in Extension either.

5. Use the rich text “kCTForegroundColorAttributeName” can’t use, will without effect, can be replaced with “NSAttributedStringKey. ForegroundColor”. PS: Everything else is going to have an effect that doesn’t require NSAttributedStringKey. Of course you can do it all with NSAttributedStringKey points for security

If you want to use Float32 or Float64, you will not receive the value in Float32 or Float64. If you want to use Float32 or Float64, you will not receive the value in Float32. The author received a value after using it.

7. The UICollectionview method has been modified

If it is swift2.3 era written as shown below:



It can continue to be used in swift3 era because of compatibility

But now swift4 will be invalid. Note that the invalid will not report errors or warn you

The new method is shown below:




8. func numberOfSectionsInTableView(_ tableView: UITableView) -> Int method is also changed to func numberOfSections(in tableView: UITableView) -> Int in the new version

At present, the main project has been switched to Swift4.1, and the above pit was found in the process of switching. If new discoveries are made later, we will continue to update. I also hope that other friends who have new discoveries can share their experience.