CocoaPods and Swift 3.0

20,587

Solution 1

What you're asking is not possible. Xcode builds your Cocoapods dependencies as well as your project. You cannot mix Swift 2.x and Swift 3 code in the same project or use Cocoapods with Swift 3 that are written in Swift 2.x.

Solution 2

Just use the following commands in the end of your podfile and it sets up your pods file to have the frameworks take the swift 3 compiler or legacy compiler automatically so you do not get the cannot use swift 2.1 in swift 3 and errors like that.

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['SWIFT_VERSION'] = '3.0'
    end
  end
end

Using this, have a look at the following example of my podfile. Just make sure the end statement is not before the block I have written above.

platform :ios, '8.0'
use_frameworks!

target 'Project 1'

pod 'FacebookCore'
pod 'FacebookLogin'
pod 'FacebookShare'

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['SWIFT_VERSION'] = '3.0'
    end
  end
end

Solution 3

This might help Swift migration guide

Straight from Swift.org

Using Carthage/CocoaPods Projects

If you are using binary Swift modules from other projects that are not built along with your project in your Xcode workspace, you can choose from one of the following migration strategies:

  1. Include the source code of the project in your Xcode workspace With this approach you will build and migrate the open-source project along with your own project.
  2. Use Xcode 7.3[.1] to make the necessary changes and validate that the project builds and links everything correctly.
  3. Include the other Xcode project files in your workspace and setup your scheme for building the targets that your project depends on. If you have setup framework search paths for finding the binary Swift modules inside Carthage’s build folder, either remove the search paths or clean the build folder, so that you are sure that you are only using the Swift modules that are built from your Xcode workspace.

Wait until the upstream open-source project updates to Swift 2.3 or Swift 3

You can follow this workflow for migrating your project:

  1. Keep your project as it is building with Xcode 7.3
  2. Invoke the migration assistant and apply the source changes that are suggested for your own project only (for Swift 2.3 or Swift 3)
  3. Before trying to build, modify the Carthage/CocoaPods dependency file and specify the specific tag/branch of the project that is migrated to Swift 2.3 or Swift 3; update your dependencies and try to build your project with the updated dependencies and the source changes that you got from the migrator.
Share:
20,587
Guilherme Torres Castro
Author by

Guilherme Torres Castro

Updated on July 09, 2022

Comments

  • Guilherme Torres Castro
    Guilherme Torres Castro almost 2 years

    I just want to try Swift 3.0 in one of my projects. Xcode open the migration window to update my project to use Swift 3.0.

    The problem is, I just want to to update my project, and leave the Pods project untouched because any changes will be discard after I run the pod install again.

    Anyone already have a solution for that?