ios 使用 swift 运行 pod install 时出错

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29091522/
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 05:13:53  来源:igfitidea点击:

Error running pod install with swift

iosswiftcocoapods

提问by channa ly

I followed the instruction from Cocoapods.

我遵循了 Cocoapods 的指示。

Below is my Podfile:

以下是我的 Podfile:

platform :ios, '8.2'

pod 'SwiftyJSON', '~> 2.1'
pod 'SwiftSpinner', '~> 0.6'
pod 'Alamofire', '~> 1.1'
pod 'SuperRecord', '~> 1.2'
pod 'Toucan

When I did pod installI got the following error:

当我执行pod install 时,出现以下错误:

Pods written in Swift can only be integrated as frameworks; this feature is still in beta. Add use_frameworks!to your Podfile or target to opt into using it.

用 Swift 编写的 Pod 只能集成为框架;此功能仍处于测试阶段。添加use_frameworks!到您的 Podfile 或目标以选择使用它。

Updated:

更新:

Below is my console log:

下面是我的控制台日志:

$ pod install
Analyzing dependencies
Downloading dependencies
Installing Alamofire (1.1.4)
Installing SuperRecord (1.2)
Installing SwiftSpinner (0.6.0)
Installing SwiftyJSON (2.1.3)
Installing Toucan (0.2.0)
[!] Pods written in Swift can only be integrated as frameworks; this feature is still in beta. Add `use_frameworks!` to your Podfile or target to opt into using it.

回答by Meet

Add "use_frameworks!" to your Podfile:

添加“use_frameworks!” 到您的 Podfile:

Please see below sample Podfile

请参阅下面的示例 Podfile

target 'MySample' do

  pod 'AFNetworking', '~> 2.5'

  pod 'Net', '~> 0.2' #This is a sample in Swift

  use_frameworks! # <--Use this line
end

回答by gagarwal

Add "use_frameworks!" to your Podfile because:

添加“use_frameworks!” 到您的 Podfile,因为:

Because Apple doesn't let you build static libraries that contain Swift. Unlike Objective-C, Apple doesn't ship the Swift standard runtime libraries with iOS. This decouples the language version from the platform version. When you build an app with Swift, you're responsible yourself to ship them. By default, Xcode uses swift-stdlib-tool to handle copying the Swift runtime dylibs, but the tooling falls short when attempting to ship frameworks that use Swift with an app that is Objective-C only. Your app executable and the frameworks you ship will all use the same set of dylibs, which are embedded into the Frameworks subdirectory of the application bundle.

First, that's because you can't link against different versions of the standard libraries. Furthermore it is desirable to embed them only once and not multiple times, because of constraints to memory size and network speed, which are relevant for distribution. You can make CocoaPods integrate to your project via frameworks instead of static libraries by specifying use_frameworks!. If that's not present, you won't be able to integrate dependencies, if you depend on a pod which includes Swift source code.

因为 Apple 不允许您构建包含 Swift 的静态库。与 Objective-C 不同,Apple 没有随 iOS 一起提供 Swift 标准运行时库。这将语言版本与平台版本分离。当您使用 Swift 构建应用程序时,您有责任交付它们。默认情况下,Xcode 使用 swift-stdlib-tool 来处理 Swift 运行时 dylib 的复制,但是在尝试将使用 Swift 的框架与仅使用 Objective-C 的应用程序一起发布时,该工具会出现不足。您的应用程序可执行文件和您提供的框架都将使用相同的 dylib 集,它们嵌入到应用程序包的 Frameworks 子目录中。

首先,这是因为您无法链接不同版本的标准库。此外,由于与分发相关的内存大小和网络速度的限制,最好只嵌入一次而不是多次嵌入它们。您可以通过指定 use_frameworks! 使 CocoaPods 通过框架而不是静态库集成到您的项目中。如果它不存在,如果您依赖包含 Swift 源代码的 pod,您将无法集成依赖项。

Reference: http://blog.cocoapods.org/CocoaPods-0.36/

参考:http: //blog.cocoapods.org/CocoaPods-0.36/

回答by Mina Fawzy

as it written in Podfile it says uncomment use_frameworks! is your are using Swift so all you have to do uncomment this line and all works just fine

正如它在 Podfile 中写的那样,它说取消注释 use_frameworks!您是否正在使用 Swift,因此您只需取消注释此行,一切正常

# Uncomment this line to define a global platform for your project
# platform :ios, '8.0'
# Uncomment this line if you're using Swift
use_frameworks! 

target 'YourProjectName' do
  pod 'SwiftyJSON', '~> 2.1'
  pod 'SwiftSpinner', '~> 0.6'
  pod 'Alamofire', '~> 1.1'
  pod 'SuperRecord', '~> 1.2'
  pod 'Toucan'
  # all other pods goes here 
end

target 'YourProjectName' do

end

target 'YourProjectName' do

end

回答by Yogesh Dalavi

I my case i used to upgrade cocoapods by command sudo gem install cocoapodsand my issue got resolved. I used objective - c as well as swift libraries in my project.

我的情况是我曾经通过命令升级 cocoapods sudo gem install cocoapods,我的问题得到了解决。我在我的项目中使用了objective - c 以及 swift 库。

回答by joan checo cigollen

the solution is very simple. You only have to add these lines to your pod file:

解决方法很简单。您只需将这些行添加到您的 pod 文件中:

target 'PassDTAFirebase' do

  inherit! :complete

    # Here your pods

  use_frameworks! 

end