7

I know cocoapod is simplifying the efforts of manually adding libraries or let developer concentrate on his actual source code.

But my question is if I need only some of source file from certain project then is good to add whole library by installing same cocoapod? Like if I need only Reachability class file then why should I take whole AFNetworking

Isn't it creating code redundancy or increasing my iPA size or other performance issues?

2 Answers 2

10

In general, adding a static library to your project in Objective-C will pull ALL OBJECT FILES into your resulting binary because cocoa pods installation adds -ObjC flag to your linker settings, and as stated in linker manual:

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

This flag included to solve problem with linking categories, because by default linker will not include object files containing only categories into resulting binary.

So, in general, be carefull when adding a big library to you project via CocoaPods.

Sign up to request clarification or add additional context in comments.

3 Comments

I have facebook sdks (which is written in objective c) in my swift project. Any solution with swift?
So adding the same big library manually instead of via CocoaPods will not increase the size of the IPA the same?
Iulian Onofrei, it is the problem of all static libraries written in ObjC, no matter cocoapods. If library is written in C/C++ compiler will work fine with that. In you need to optimize binary size - look towards adding it as a source code or splitting pod into smaller libraries and adding needed one
7

AFNetworking is divided into subspecs, so you should be able to get just the reachability part with:

pod 'AFNetworking/Reachability'

or you can get a different more focused pod, search for reachability on cocoapods.org

In terms of general code waste: I wouldn't be too worried about IPA size for relatively small libraries like AFNetworking (270K on disk of source). In terms of including code you don't use I guess you should try and find a library that most closely matches your needs. If you have a choice between writing exactly the networking code you need, or use a tried and proven framework even though you don't use it all, i'd take the framework

1 Comment

hi, reachability is just an example I explained.I am looking for overall pod concept..can you please edit and generalise the use performance of cocoapod?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.