ios CocoaPods 和 Swift 3.0

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37821560/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 09:22:31  来源:igfitidea点击:

CocoaPods and Swift 3.0

iosswiftswift3cocoapodsxcode8

提问by Guilherme Torres Castro

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.

我只想在我的一个项目中尝试 Swift 3.0。Xcode 打开迁移窗口以更新我的项目以使用 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 installagain.

问题是,我只想更新我的项目,并保持 Pods 项目不变,因为在我pod install再次运行后任何更改都将被丢弃。

Anyone already have a solution for that?

有人已经有解决方案了吗?

回答by JAL

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.

你问的是不可能的。Xcode 构建您的 Cocoapods 依赖项以及您的项目。您不能在同一个项目中混合使用 Swift 2.x 和 Swift 3 代码,也不能将 Cocoapods 与用 Swift 2.x 编写的 Swift 3 一起使用。

回答by Asfand Shabbir

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.

只需在您的 podfile 末尾使用以下命令,它就会设置您的 pods 文件,让框架自动采用 swift 3 编译器或遗留编译器,这样您就不会在 swift 3 中遇到 cannot use swift 2.1 和类似的错误。

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.

使用这个,看看我的 podfile 的以下示例。只要确保结束语句不在我上面写的块之前。

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

回答by harsh_v

This might help Swift migration guide

这可能有助于Swift 迁移指南

Straight from Swift.org

直接来自 Swift.org

Using Carthage/CocoaPods Projects

使用 Carthage/CocoaPods 项目

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:

如果您正在使用其他项目中的二进制 Swift 模块,而这些模块并未与您的 Xcode 工作区中的项目一起构建,您可以选择以下迁移策略之一:

  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.
  1. 在您的 Xcode 工作区中包含项目的源代码 通过这种方法,您将构建和迁移开源项目以及您自己的项目。
  2. 使用 Xcode 7.3[.1] 进行必要的更改并验证项目是否正确构建和链接所有内容。
  3. 将其他 Xcode 项目文件包含在您的工作区中,并设置用于构建项目所依赖的目标的方案。如果您在 Carthage 的构建文件夹中设置了用于查找二进制 Swift 模块的框架搜索路径,请删除搜索路径或清理构建文件夹,以确保您仅使用从 Xcode 工作区构建的 Swift 模块。

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

等到上游开源项目更新到 Swift 2.3 或 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.
  1. 保留您的项目,因为它是使用 Xcode 7.3 构建的
  2. 调用迁移助手并应用仅为您自己的项目建议的源更改(适用于 Swift 2.3 或 Swift 3)
  3. 在尝试构建之前,修改 Carthage/CocoaPods 依赖文件并指定迁移到 Swift 2.3 或 Swift 3 的项目的具体标签/分支;更新您的依赖项并尝试使用更新后的依赖项和从迁移器获得的源更改来构建您的项目。

回答by ronak patel

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

使用最新的 cocoapods 的任何 xcode 并删除 cocoapods 并再次安装最新的这一步在 swift 3.0 中正常工作我在 swift 3.0 中使用

0.sudo gem install cocoapods

0.sudo gem 安装 cocoapods

1.cd (drag and drop your project folder)

1.cd(拖放你的项目文件夹)

2.sudo gem install cocoapods

2.sudo gem 安装 cocoapods

3.touch podfile //create podfile

3.touch podfile //创建podfile

4.open -e podfile

4.open -e podfile

5.platform :ios, '10.0' use_frameworks!

5.platform :ios, '10.0' use_frameworks!

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

目标 '' do pod 'Alamofire', '~> 4.4' end

6.ctrl+s

6.ctrl+s

7.ctrl+q

7.ctrl+q

8.pod install

8.pod安装