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

Framework Oriented Programming (NSBudapest)

Framework Oriented Programming (NSBudapest)

Learn how to modularize your app and reuse your business logic across products, platforms, and projects.

Pedro Piñera Buendía

June 29, 2016
Tweet

More Decks by Pedro Piñera Buendía

Other Decks in Technology

Transcript

  1. CONTEXT 2008 ! LAUNCHES IPHONE SOFTWARE DEVELOPMENT KIT " (Developers

    move to iOS. New platform, frameworks,... New exciting area)
  2. CONTEXT After 2011 ! - 1 TARGET " ! -

    1 TARGET " X TARGETS (EXTERNAL) !!
  3. CONTEXT 2015 ! - 1 TARGET ! - 1 TARGET

    ! - 1 TARGET ⌚ - 1 TARGET
  4. 6. FINAL SOLID INSPIRED (OPEN/CLOSED) final class Person { let

    name: String } class Alien: Person { // Compiler complains }
  5. 7. FRAMEWORK MODELS DON'T SHARE FRAMEWORKS' MODELS UPWARDS // Persistence

    class Author: NSManagedObjectModel { let name: String } class Track: NSManagedObjectModel { let author: Author } // ListenersKit struct StreamTrackEntity { let name: String let authorName: String }
  6. 7. FRAMEWORK MODELS DON'T SHARE FRAMEWORKS' MODELS UPWARDS struct StreamTrackEntityAdapter

    { func adapt(track: Track) -> StreamTrackEntity { return StreamTrackEntity(name: track.name, authorName: track.author.name) } }
  7. 10. CORE/TESTING (AKA YOUR PROJECT FOUNDATION FRAMEWORKS) ▸ Extensions ▸

    Logging ▸ Analytics ▸ Architectural components (e.g. Reactive)
  8. OPEN SOURCE And benefit from the community BUILD PIECES OF

    CODE THAT YOU'D BE PROUD OF OPEN SOURCING
  9. CocoaPods ▸ ✅ Easy setup (each Framework .podspec) ▸ ✅

    Same setup for local/external dependencies ▸ ❌ It sucks if you don't version ▸ ❌ Fully frameworks approach (load time)
  10. Manual ▸ ✅ More control over the workspace ▸ ✅

    Custom setup (you design it) ▸ ❌ Cumbersome setup (Build Settings) External dependencies can be checked out with Carthage/Git Submodules
  11. SUPPORTED_PLATFORMS = iphoneos iphonesimulator appletvsimulator appletvos macosx watchsimulator watchos TARGETED_DEVICE_FAMILY[sdk=iphone*]

    = 1,2 TARGETED_DEVICE_FAMILY[sdk=watch*] = 4 TARGETED_DEVICE_FAMILY[sdk=appletv*] = 3 VALID_ARCHS[sdk=macosx*] = x86_64 LD_RUNPATH_SEARCH_PATHS[sdk=iphone*] = $(inherited) @executable_path/Frameworks @loader_path/Frameworks LD_RUNPATH_SEARCH_PATHS[sdk=macosx*] = $(inherited) @executable_path/../Frameworks @loader_path/../Frameworks LD_RUNPATH_SEARCH_PATHS[sdk=watch*] = $(inherited) @executable_path/Frameworks @loader_path/Frameworks LD_RUNPATH_SEARCH_PATHS[sdk=appletv*] = $(inherited) @executable_path/Frameworks @loader_path/Frameworks
  12. Hybrid ▸ ✅ CocoaPods resolves/integrates app dependencies ▸ ✅ Carthage

    resolves frameworks dependencies ▸ ✅ Custom stack setup
  13. 1. Keep it in the same repository (fast iterations) 2.

    Move it once it consolidates (sporadic changes) 3. Then version it! (snapshots in time)
  14. ▸ If CocoaPods for local: Use it also for external

    ▸ If manual setup: Use Carthage or Git Submodules
  15. ▸ Objective-C & not shared - Static ▸ Objective-C &&

    shared - Dynamic ▸ Swift - Dynamic
  16. ▸ No more than 6 - (WWDC2016:406) ▸ Group dependencies

    in Framework (Manual setup) Testing.framework Quick.{swift,h,m} Nimble.{swift,h,m} OHHTTPStubs.{swift,h,m} Core.framework RxSwift{.swift}
  17. IS IT A COMPANY OR A FREELANCE PROJECT? IS IT

    A NEW PROJECT? AM I USING ANY DEPENDENCIES TOOL?
  18. IS IT A COMPANY OR A FREELANCE PROJECT? IS IT

    A NEW PROJECT? AM I USING ANY DEPENDENCIES TOOL? HOW MANY PEOPLE IN THE TEAM?
  19. REFERENCES ▸ Library Oriented Programming: Justin Spahr-Summers ▸ The Unofficial

    Guide to xcconfig files ▸ WWDC: Optimizing App Startup Time ▸ Static & Dynamic libraries ▸ pepibumur/framework-oriented-programming