ios 为什么我们在 CocoaPods 中使用 use_frameworks?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41210249/
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
Why do we use use_frameworks in CocoaPods?
提问by harikrista
I have used use_frameworks
in CocoaPods Podfile
many times. I just wonder why do we use it? I couldn't get the straight forward answer of it.
我use_frameworks
在 CocoaPods 中使用过Podfile
很多次。我只是想知道我们为什么要使用它?我无法得到直接的答案。
Example:
例子:
platform :ios, '8.0'
use_frameworks!
target "CityWhether" do
pod 'Alamofire'
pod 'SwiftyJSON'
end
回答by FelixSFD
use_frameworks
tells CocoaPods that you want to use Frameworks instead of Static Libraries. Since Swift does not support Static Libraries you have to use frameworks.
use_frameworks
告诉 CocoaPods 你想使用框架而不是静态库。由于 Swift 不支持静态库,因此您必须使用框架。
In another answer, I explained the differences between Static Libraries and Frameworks:
在另一个答案中,我解释了静态库和框架之间的区别:
Cocoa Touch Frameworks
They are always open-source and will be built just like your app. (So Xcode will sometimes compile it, when you run your app and always after you cleaned the project.) Frameworks only support iOS 8 and newer, but you can use Swift and Objective-C in the framework.
Cocoa Touch Static Libraries
As the name says, they are static. So they are already compiled, when you import them to your project. You can share them with others without showing them your code. Note that Static Libraries currently don't support Swift. You will have to use Objective-C within the library. The app itself can still be written in Swift.
Cocoa Touch 框架
它们始终是开源的,并且将像您的应用程序一样构建。(所以 Xcode 有时会编译它,当你运行你的应用程序时,总是在你清理项目之后。)框架只支持 iOS 8 和更新版本,但你可以在框架中使用 Swift 和 Objective-C。
Cocoa Touch 静态库
顾名思义,它们是静态的。因此,当您将它们导入项目时,它们已经被编译。您可以与他人共享它们,而无需向他们展示您的代码。请注意,静态库目前不支持 Swift。您将不得不在库中使用 Objective-C。应用程序本身仍然可以用 Swift 编写。
Sources: My other answer| AddThis.com Blog
资料来源:我的另一个答案| AddThis.com 博客
回答by JosephH
use_frameworks!
tells cocoa pods to use dynamic libraries, and was very prevalent at one point due in particular to swift not supporting static libraries, meaning there was no choice - however you often don'tneed use_frameworks!
anymore.
use_frameworks!
告诉可可豆荚使用动态库,并且在某一时刻非常流行,特别是由于 swift 不支持静态库,这意味着别无选择 - 但是您通常不再需要use_frameworks!
了。
As of Xcode 9 beta 4, and CocoaPods 1.5.0, swift static libraries are now supported. The main advantage is faster app startup times, particularly if you have a lot of pods - iOS 10 and 11 are not the fastest when you have many dylibs.
从 Xcode 9 beta 4 和 CocoaPods 1.5.0 开始,现在支持 swift 静态库。主要优点是应用程序启动时间更快,尤其是当你有很多 pod 时——当你有很多 dylib 时,iOS 10 和 11 并不是最快的。
CocoaPods 1.5.0 was released in early April 2018, so you may need to upgrade to get it: sudo gem install cocoapods
.
CocoaPods 1.5.0 于 2018 年 4 月上旬发布,因此您可能需要升级以获取它:sudo gem install cocoapods
.
I've found several pods that don't work correctly with static libraries yet though, so your mileage may vary.
不过,我发现有几个 pod 不能与静态库一起正常工作,因此您的里程可能会有所不同。
回答by mistdon
use_frameworks
declares that you want to use dynamic frameworks, instead of static libraries.
use_frameworks
声明您要使用动态框架,而不是静态库。
With Xcode 9.0 and CocoaPods 1.5.0 released, you could use static libraries with swift if you do not use use_frameworks
.
随着 Xcode 9.0 和 CocoaPods 1.5.0 的发布,如果您不使用use_frameworks
.
One problem with use_frameworks
is that all your framework in Pods/Products are frameworks.
一个问题use_frameworks
是你在 Pods/Products 中的所有框架都是框架。
Here is a related article: Basic overview of static and dynamic frameworks on ios
这是一篇相关文章:ios上静态和动态框架的基本概述
回答by yoAlex5
Cocoapod's[About]use_frameworks!
is responsible for the type of binary:
Cocoapod的[About]use_frameworks!
负责binary的类型:
- if
use_frameworks!
is present-dynamic framework
- if
use_frameworks!
is not present-static library
- 如果
use_frameworks!
是现在-dynamic framework
- 如果
use_frameworks!
是不存在的-static library
use_frameworks!
has a reflection in Mach-O Type
[About]in a corresponding target of Pods
project.
use_frameworks!
在项目的相应目标中的Mach-O Type
[About]中有反映Pods
。
Timeline:
时间线:
- CocoaPods 0.36introduced
use_frameworks!
which you had to use for Swift pod - CocoaPods 1.5.0and Xcode 9 allowed you to have a choice
- 引入了CocoaPods 0.36
use_frameworks!
,您必须将其用于 Swift pod - CocoaPods 1.5.0和 Xcode 9 让你有了选择
回答by Chiara
Adding
添加
use_frameworks!
使用_框架!
in the Podfile means that we want the listed frameworks to be dynamically installed instead as static frameworks.
在 Podfile 中意味着我们希望将列出的框架动态安装而不是作为静态框架。