Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Brew Your Own Cocoa Framework

Brew Your Own Cocoa Framework

In this session, I will discuss how to design, implement, distribute, and use a Cocoa Frameworks. The talk would start describing the different options available (Cocoa touch frameworks, static frameworks and development Cocoapods), following a set of guidelines to (re)architect the code into a modular design and finalizing with some recommendations about swift integration, version management, code documentation and testing; including unit and code coverage. I'm planning to illustrate the talk with a small project that refactor some code, wrap it in a framework and later is used in another application.

Billy Tobon

June 10, 2015
Tweet

Other Decks in Programming

Transcript

  1. What is a framework? “A software framework is a universal,

    reusable software environment that provides particular functionality as part of a larger software platform to facilitate development of software applications, products and solutions...” -- wikipedia
  2. bonus points » (Re)learn your code » Pay your technical

    debt » Opportunity to start or improve Unit tests » A chance to document your code
  3. What options do we have? » Share source files »

    Cocoa Touch Library (Static) » Cocoa Touch Framework (Dynamic)
  4. Cocoa Touch Framework » New in XCode 6 and iOS

    8 » Easy setup » Same look and feel as Apple frameworks » Bundle, not source code
  5. What goes in a framework? » Classes [.h | .m

    | .swift] » Assets (Images, fonts, icons) » Custom UI elements @IBDesignable
  6. Without Dependecy Injection -(void) doSomething { NSArray *tshirts = [ShirtService

    sharedInstance].tshirts Dlog(@"We have %d designs",[tshirts count]); } With Dependecy Injection -(void) doSomething:ShirtService *shirtService { NSArray *tshirts = shirtService.tshirts Dlog(@"We have %d designs",[tshirts count]); }
  7. façade pattern //RENTKit.h @interface RENTKit:NSObject +(BOOL) rentDressWithSKU:(NSString *)sku; @end //RENTKit.m

    @implementation +(BOOL) rentDressWithSKU:(NSString *)sku{ [[RTRKit sharedInstance] rentWithSKU:sku]; } -(BOOL) rentWithSKU:(NSString *)sku{ //some business logic return true; } @end //Framework use [RENTKit rentDressWithSKU:@"31415"];
  8. Examples » Google Style Guide » New York Times Style

    Guide » raywenderlich.com » GitHub
  9. Distribution blues: » Need a framework per architecture (sim/device): »

    Simulator i386 x86_64 » Device armv7 armv7s arm64 » use lipo tool to create a fat binary » Decide the framework depending the build configuration and Architecture
  10. Assets Objective-C NSBundle *aBundle = [NSBundle bundleWithIdentifier:@"altconf.MyLittleFramework"]; UIImage *im =

    [UIImage imageNamed:@"nice_image" inBundle:aBundle compatibleWithTraitCollection:nil]; Swift let image = UIImage(named: "nice_image", inBundle: NSBundle(forClass: MyLittleFramework.self), compatibleWithTraitCollection: nil)
  11. Images attribution » Hot Cocoa lanielderts - flickr.com/photos/ lanielderts/ »

    Cocoapods Icon - cocoapods.org » Carthage Icon - github.com/Carthage/Carthage » Apple Watch - clockmaker-jp flickr.com/photos/ clockmaker-jp/ » Wishbone jamesjordan - flickr.com/photos/ jamesjordan/