Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CocoaPods and Swift 3.0

Tags:

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?

like image 367
Guilherme Torres Castro Avatar asked Jun 14 '16 20:06

Guilherme Torres Castro


People also ask

Can a Swift package use CocoaPods?

As of writing, the Swift Package Manager (SPM) is in "early design and development" [1]. It does not currently support iOS, watch OS, or Objective-C [2][3]. CocoaPods will continue development supporting both Swift and Objective-C while SPM develops.

Can you use CocoaPods and Swift package manager?

Cocoapods and SwiftPM are some of the most popular package managers. By supporting both in your open-source library, you potentially increase the developers who will use it. 🚨Remember the most important thing all package managers want to know is where are the source files in order to distribute them.

What is latest version of CocoaPods?

1.11. 0. beta. 1 - August 09, 2021 (286 KB)


3 Answers

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.

like image 109
JAL Avatar answered Sep 28 '22 19:09

JAL


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
like image 33
Asfand Shabbir Avatar answered Sep 28 '22 20:09

Asfand Shabbir


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.
like image 29
harsh_v Avatar answered Sep 28 '22 20:09

harsh_v