Why do we use use_frameworks in CocoaPods?

て烟熏妆下的殇ゞ 提交于 2019-11-26 12:06:17

问题


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.

Example:

platform :ios, \'8.0\'
use_frameworks!

target \"CityWhether\" do
    pod \'Alamofire\'
    pod \'SwiftyJSON\'
end

回答1:


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.


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.

Sources: My other answer | AddThis.com Blog




回答2:


You don't have to "use_frameworks!" anymore.

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.

CocoaPods 1.5.0 was released in early April 2018, so you may need to upgrade to get it: sudo gem install cocoapods.

I've found several pods that don't work correctly with static libraries yet though, so your mileage my vary.




回答3:


use_frameworks! declared that you want to use dynamic framework, instead of static libraries.

With Xcode 9.0 and CocoaPods 1.5.0 released. you could use static libraries with swift if you do not use use_frameworks.

One performance with use_frameworks is that all your framework in Pods/Products is frameworks.

Here is a related article: Basic overview of static and dynamic frameworks on ios




回答4:


Adding

use_frameworks!

in the Podfile means that we want the listed frameworks to be dynamically installed instead as static frameworks.




回答5:


use_frameworks! in the podfile demonstrates that it will be supported iOS 8.0 and later. It doesn't support iOS 7.0 for all of cocoapods libs.

If you want to the project to support iOS 7.0 and later , you must delete it.

So changes is blow

platform :ios, '7.0' target "CityWhether" do end



来源:https://stackoverflow.com/questions/41210249/why-do-we-use-use-frameworks-in-cocoapods

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