Your SlideShare is downloading. ×
Building static libraries for iOS with CocoaPods
Building static libraries for iOS with CocoaPods
Building static libraries for iOS with CocoaPods
Building static libraries for iOS with CocoaPods
Building static libraries for iOS with CocoaPods
Building static libraries for iOS with CocoaPods
Building static libraries for iOS with CocoaPods
Building static libraries for iOS with CocoaPods
Building static libraries for iOS with CocoaPods
Building static libraries for iOS with CocoaPods
Building static libraries for iOS with CocoaPods
Building static libraries for iOS with CocoaPods
Building static libraries for iOS with CocoaPods
Building static libraries for iOS with CocoaPods
Building static libraries for iOS with CocoaPods
Building static libraries for iOS with CocoaPods
Building static libraries for iOS with CocoaPods
Building static libraries for iOS with CocoaPods
Building static libraries for iOS with CocoaPods
Building static libraries for iOS with CocoaPods
Building static libraries for iOS with CocoaPods
Building static libraries for iOS with CocoaPods
Building static libraries for iOS with CocoaPods
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Building static libraries for iOS with CocoaPods

2,122

Published on

If you ever wondered how to easily develop and manage your own libraries for iOS and OS X seek no further! Watch the presentation and read our blog to find a solution. If you have any questions just …

If you ever wondered how to easily develop and manage your own libraries for iOS and OS X seek no further! Watch the presentation and read our blog to find a solution. If you have any questions just drop me an email or tweet :)

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,122
On Slideshare
0
From Embeds
0
Number of Embeds
7
Actions
Shares
0
Downloads
9
Comments
0
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Building static libraries for iOS with kamil.burczyk@sigmapoint.pl
  • 2. • What is CocoaPods? • Local CocoaPods dependencies. • Building a distribution library. • One library - 5 different architectures. • Avoiding collisions in other projects. • Final thoughts. Roadmap:
  • 3. CocoaPods is the dependency manager for Objective-C projects. It has thousands of libraries and can help you scale your projects elegantly. [http://cocoapods.org]
  • 4. Podfile: pod 'CocoaLumberjack', '~> 1.7.0' pod 'AFNetworking', '~> 1.3.3' pod 'UIView+AutoLayout', '~> 1.1.0' pod 'MagicalRecord', '~> 2.2' pod 'Reachability', '~> 3.1.1' pod 'UIAlertView-Blocks', '~> 0.0.1' Terminal: $ pod install
  • 5. Semantic versioning: ! • Major.Minor.Patch -> 2.0.1 • Major - incompatible API changes • Minor - added features but backward compatible • Patch - backward compatible bug fixes int add(int a, int b) { return a-b; } // 1.0.0 double add(int a) { return 3.14+a; } int add(int a, int b, int c=0) { return a+b+c; } int add(int a, int b) { return a+b; } // x.y.z
  • 6. CocoaPods project structure
  • 7. Podspec file Pod::Spec.new do |s| s.name = "NetworkLib" s.version = “1.0.0” s.platform = :ios, '7.0' s.source_files = 'NetworkLib', 'NetworkLib/**/*.{h,m}' s.public_header_files = 'NetworkLib/**/*.h' s.resources = "NetworkLib/*.png" s.framework = 'SystemConfiguration' s.requires_arc = true s.dependency 'AFNetworking' end
  • 8. Local CocoaPods dependency $ pod 'NetworkLib', :path => '../NetworkLib' git fork CocoaPods dependency $ pod 'WebViewJavascriptBridge', :git => ‘https://github.com/burczyk/WebViewJavascriptBridge/', :commit => '5183c4c'
  • 9. Demo #1
  • 10. Building distribution library xcodebuild -workspace NetworkLib.xcworkspace -scheme NetworkLib -sdk iphonesimulator -configuration Debug lipo -create lib1.a lib2.a -output libMultipleArch.a
  • 11. Aggregate Lib script
  • 12. Build all supported architectures $ lipo —info libNetworkingLib-debug-0.1.a ! ! Architectures in the fat file: libNetworkLib-debug-0.1.a are: armv7 armv7s i386 x86_64 arm64
  • 13. Copy files phase & results
  • 14. Demo #2
  • 15. Symbol collisions What happens if user adds AFNetworking to his app?
  • 16. Symbols investigation $ nm libNetworkLib-debug-0.1.a | grep AFN ! ! 000000000000bea0 s -[UIWebView(_AFNetworking) af_HTTPRequestOperation].eh ! 0000000000000030 t -[UIWebView(_AFNetworking) af_setHTTPRequestOperation:] ! 000000000000bec8 s -[UIWebView(_AFNetworking) af_setHTTPRequestOperation:].eh ! 0000000000000190 t ___44-[UIWebView(AFNetworking) requestSerializer]_block_invoke ! 000000000000bf18 s ___44-[UIWebView(AFNetworking) requestSerializer]_block_invoke.eh
  • 17. Symbol collisions solutions • Pretend they don’t exist ;) • Write in docs which dependencies are required • Export all dependencies’ headers • Build library with prefixed symbols
  • 18. Exporting all symbols http://pdx.esri.com/blog/2013/12/13/namespacing-dependencies/ nm $CODESIGNING_FOLDER_PATH -j | sort | uniq | grep "_OBJC_CLASS_$_" | grep -v "$_NS" | sed … //NamespacedDependencies.h: ! #ifndef AFHTTPSessionManager #define AFHTTPSessionManager __NS_SYMBOL(AFHTTPSessionManager) #endif AFHTTPSessionManager —> SIGMA_AFHTTPSessionManager
  • 19. Configuring Pods & lib to use prefixed symbols
  • 20. Symbols re-investigation $ nm libNetworkLib-debug-0.1.a | grep SIGMA ! ! 000000000000b720 s l_OBJC_ $_CATEGORY_SIGMA_AFURLConnectionOperation_$__UIProgressView ! 000000000000b6d8 s l_OBJC_ $_PROP_LIST_SIGMA_AFURLConnectionOperation_ $__UIProgressView ! U _OBJC_CLASS_$_SIGMA_AFHTTPRequestOperation ! U _OBJC_CLASS_$_SIGMA_AFHTTPRequestSerializer ! U _OBJC_CLASS_$_SIGMA_AFHTTPResponseSerializer
  • 21. Demo #3
  • 22. • Easy development • Clean git repo • Easy switching from local podspec to static library • Shell & classic build script sometimes necessary • Only one step to put your lib to global repo Summary
  • 23. Contact: kamil.burczyk@sigmapoint.pl @KamilBurczyk Thank you! Links: http://cocoapods.org/ http://pdx.esri.com/blog/2013/12/13/namespacing-dependencies/ http://blog.sigmapoint.pl/

×