Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

working with cocoapods ios

Tags:

ios

cocoapods

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?

like image 444
Preetam Jadakar Avatar asked Nov 19 '13 10:11

Preetam Jadakar


2 Answers

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.

like image 188
Andrei Shender Avatar answered Oct 19 '22 00:10

Andrei Shender


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

like image 39
wattson12 Avatar answered Oct 19 '22 01:10

wattson12