Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Xcode8 with a swift 2.3 project that uses cocoapods

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?

like image 867
Alex Bollbach Avatar asked Jul 27 '16 16:07

Alex Bollbach


2 Answers

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.

like image 139
Buntylm Avatar answered Oct 16 '22 11:10

Buntylm


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).

like image 31
Deyton Avatar answered Oct 16 '22 11:10

Deyton