Building static libraries
for iOS with
kamil.burczyk@sigmapoint.pl
• What is CocoaPods?
• Local CocoaPods dependencies.
• Building a distribution library.
• One library - 5 different archit...
CocoaPods is the dependency manager for
Objective-C projects. It has thousands of
libraries and can help you scale your pr...
Podfile:
pod 'CocoaLumberjack', '~> 1.7.0'
pod 'AFNetworking', '~> 1.3.3'
pod 'UIView+AutoLayout', '~> 1.1.0'
pod 'MagicalR...
Semantic versioning:
!
• Major.Minor.Patch -> 2.0.1
• Major - incompatible API changes
• Minor - added features but backwa...
CocoaPods project structure
Podspec file
Pod::Spec.new do |s|
s.name = "NetworkLib"
s.version = “1.0.0”
s.platform = :ios, '7.0'
s.source_files = 'Netw...
Local CocoaPods dependency
$ pod 'NetworkLib', :path => '../NetworkLib'
git fork CocoaPods dependency
$ pod 'WebViewJavasc...
Demo #1
Building distribution library
xcodebuild
-workspace NetworkLib.xcworkspace
-scheme NetworkLib
-sdk iphonesimulator
-config...
Aggregate Lib script
Build all supported architectures
$ lipo —info libNetworkingLib-debug-0.1.a
!
!
Architectures in the fat file:
libNetworkL...
Copy files phase & results
Demo #2
Symbol collisions
What happens if user adds AFNetworking to
his app?
Symbols investigation
$ nm libNetworkLib-debug-0.1.a | grep AFN
!
!
000000000000bea0 s -[UIWebView(_AFNetworking)
af_HTTPR...
Symbol collisions solutions
• Pretend they don’t exist ;)
• Write in docs which dependencies are required
• Export all dep...
Exporting all symbols
http://pdx.esri.com/blog/2013/12/13/namespacing-dependencies/
nm $CODESIGNING_FOLDER_PATH -j | sort ...
Configuring Pods & lib to use prefixed symbols
Symbols re-investigation
$ nm libNetworkLib-debug-0.1.a | grep SIGMA
!
!
000000000000b720 s l_OBJC_
$_CATEGORY_SIGMA_AFURL...
Demo #3
• Easy development
• Clean git repo
• Easy switching from local podspec to static
library
• Shell & classic build script s...
Contact:
	 kamil.burczyk@sigmapoint.pl	 	 	 @KamilBurczyk
Thank you!
Links:
http://cocoapods.org/
http://pdx.esri.com/blog...
Upcoming SlideShare
Loading in …5
×

Building static libraries for iOS with CocoaPods

4,587 views
4,040 views

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 drop me an email or tweet :)

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

No Downloads
Views
Total views
4,587
On SlideShare
0
From Embeds
0
Number of Embeds
308
Actions
Shares
0
Downloads
20
Comments
0
Likes
7
Embeds 0
No embeds

No notes for slide

Building static libraries for iOS with CocoaPods

  1. 1. Building static libraries for iOS with kamil.burczyk@sigmapoint.pl
  2. 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. 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. 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. 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. 6. CocoaPods project structure
  7. 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. 8. Local CocoaPods dependency $ pod 'NetworkLib', :path => '../NetworkLib' git fork CocoaPods dependency $ pod 'WebViewJavascriptBridge', :git => ‘https://github.com/burczyk/WebViewJavascriptBridge/', :commit => '5183c4c'
  9. 9. Demo #1
  10. 10. Building distribution library xcodebuild -workspace NetworkLib.xcworkspace -scheme NetworkLib -sdk iphonesimulator -configuration Debug lipo -create lib1.a lib2.a -output libMultipleArch.a
  11. 11. Aggregate Lib script
  12. 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. 13. Copy files phase & results
  14. 14. Demo #2
  15. 15. Symbol collisions What happens if user adds AFNetworking to his app?
  16. 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. 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. 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. 19. Configuring Pods & lib to use prefixed symbols
  20. 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. 21. Demo #3
  22. 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. 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/

×