Reputation: 4590
I have a project with a light amount of code written in what I assume is swift 2.3 It contains and app extension also written in swift 2.3 and uses 2 Cocoapods: SwiftyJSON
and MMWormhole
. After downloading Xcode 8.3 beta, the migrator ran and I am left with almost 100 compiler errors in the one main swift file contained in SwiftyJSON
.
Basically I want to know if there is a way I can work in Xcode8 given these details. I am happy to update my own code to swift3 however I do not control the cocoapods (MMWormHole is in objective-C so I assume that Xcode converts that to whichever version of Swift it needs as it emits no compiler errors). Can I tell Xcode to use swift 2.3 globally?
Upvotes: 5
Views: 6033
Reputation: 7383
You have to set Use Legacy Swift Language Version
to YES
to make use SWIFT 2.3
code in Xcode 8
. Then add this into your Podfile
to make all of your pod targets confirm the same.
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |configuration|
configuration.build_settings['SWIFT_VERSION'] = "2.3"
end
end
end
I hope, it will help.
Upvotes: 6
Reputation: 2713
Add the following to the end of your Podfile
then run pod install
:
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '2.3'
end
end
end
Upvotes: 0
Reputation: 2368
Many open source Swift projects have branches for Swift 3 or Swift 2.3 (see this post for details on a popular approach). I checked SwiftyJSON and it appears to have a branch for Swift 3, so you could convert your app to Swift 3 and give that a try. In order to use it, change the SwiftyJSON entry in your Podfile to:
pod 'SwiftyJSON', :git => 'https://github.com/SwiftyJSON/SwiftyJSON.git', :branch => 'swift3'
It's up to the project to update for each Xcode 8 beta, so it may not be exactly working, but it is likely that there will be fewer than 100 errors.
Note: You may see a “Use Legacy Swift Language Version” error after updating everything and fixing the complier errors. This can be fixed by adding a post_install
step to your Podfile (see this GitHub issue), or by updating to CocoaPods 1.1.0.beta.1 or higher (gem install cocoapods --pre
).
Upvotes: 2
Reputation: 3952
From my experience when starting up the workspace, the SDK should ask you if you'd like to convert your code to Swift 3 or do it "later". By just selecting later, it won't migrate your code to swift 3. I must warn you though that I went through the same thing and it was almost impossible to work backwards just because you want to use the latest and greatest Xcode 8. You'll eventually run into problems such as when you're ready to push to the app store and iTunesConnect won't accept any files that are lower than version 10. Also when and if another developer inherits your code, they will have problems if they are using an earlier version of Xcode.
Upvotes: 0