Work with cocoapods ios

I know that cocoapod simplifies the effort of manually adding libraries or allows the developer to focus on his real source code.

But my question is, do I only need some source file from a specific project, then is it good to add the whole library by installing the same cocoapod? For example, if I only need a Reachability class file, then why should I take the whole AFNetworking

Doesn't that create code redundancy or increase my iPA size or other performance issues?

+6
source share
2 answers

In general, adding a static library to your project in Objective-C will result in pulling ALL OBJECTS into your resulting binary, because setting cocoa pods adds the -ObjC flag to the linker settings and, as the linker manual states:

 -ObjC Loads all members of static archive libraries that implement an Objective-C class or category. 

This flag is enabled to solve the problem with category binding, because by default the linker will not include object files containing only categories in the resulting binary file.

So, be careful when adding a large library to your project through CocoaPods.

+9
source

AFNetworking is divided into subroutines, so you should be able to get only part of the reachability:

 pod 'AFNetworking/Reachability' 

or you can get another more focused reachability block at cocoapods.org

Regarding general code loss: I wouldn’t worry too much about IPA size for relatively small libraries like AFNetworking (270K on source disk). Regarding the inclusion of code that you are not using, I think you should try to find a library that best suits your needs. If you have a choice between writing just the right network code or using a tried and tested structure, even if you don’t use all of this, I would take the framework

+7
source

Source: https://habr.com/ru/post/958376/


All Articles