CocoaPods and Swift 3.0

半腔热情 提交于 2019-11-26 20:11:16

问题


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?


回答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.




回答2:


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.



回答3:


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



回答4:


any xcode in use latest cocoapods and remove cocoapods and again install latest with this step surly work in swift 3.0 i used in swift 3.0

0.sudo gem install cocoapods

1.cd (drag and drop your project folder)

2.sudo gem install cocoapods

3.touch podfile //create podfile

4.open -e podfile

5.platform :ios, '10.0' use_frameworks!

target '' do pod 'Alamofire', '~> 4.4' end

6.ctrl+s

7.ctrl+q

8.pod install



来源:https://stackoverflow.com/questions/37821560/cocoapods-and-swift-3-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!