With the arrival of Xcode9 Swift4, some minor problems have followed. Many excellent Swift third party frameworks have not yet had time to welcome the arrival of Swift4, they are still in swift3.x state, this time to create a new project, use cocoapods to write the need to use the third party, a compilation will be full of red, as shown below.
Fortunately, Apple keeps the previous version of Swift with each update to Xcode in case of a riot 😬~~
There are two solutions that essentially control which version of Swift is used at compile time
The first: Xcode
Pods -> Targets -> SnapKit -> Build Settings -> Swift Language Version option Select Swift 3.2. It is not recommended to use this method. One point by point is a little inefficient ~~
Second: Control using Cocoapods
Open the Podfile file, add and modify the code below as needed to specify which third-party versions of Swift are compiled, and then do it again
pod install
Copy the code
One last step to compile
post_install do |installer|
# Need to specify the name of the third party to compile the version
myTargets = ['ObjectMapper'.'SnapKit']
installer.pods_project.targets.each do |target|
if myTargets.include? target.name
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '3.2'
end
end
end
end
Copy the code
The position is shown in the figure