Framework Oriented Programming - MobiConf 2016

Framework Oriented Programming - MobiConf 2016

Have you ever tried to reuse code from your mobile apps and you haven’t been able to? Did you start using frameworks only when Apple suggested it for Watch Extensions?

With more platforms coming out, there's a clear need of bundling logic that can be reused and shared in multiple platforms. Frameworks will help us with that and will benefit our application code bases in many ways.

Learn how to do it, with or without dependency manager involved, recommendations and some caveats you must keep in mind. Start building your own Foundation frameworks, reusable, well designed, and with single responsibilities.

B0a336761194918a853deeff1f22b537?s=128

Pedro Piñera Buendía

October 06, 2016
Tweet

Transcript

  1. 2.
  2. 6.
  3. 7.

    BOX

  4. 9.

    !"#

  5. 10.
  6. 11.
  7. 13.

    In computer science, a framework is a collection of implementations

    of behavior, written in terms of a language, that has a well-defined interface by which the behavior is invoked Wikipedia
  8. 15.
  9. 16.

    inhibit_all_warnings! use_frameworks! target 'MyApp' do pod "PureLayout" pod 'FLEX' pod

    'DateTools' pod 'Reachability' pod 'RxSwift' pod 'SDWebImage' pod "SDVersion" pod 'BlocksKit' pod 'CTFeedback' pod 'TOWebViewController' pod '1PasswordExtension' pod 'SlackTextViewController' pod 'FeedbackMe' pod 'Localize-Swift' pod 'Smooch' pod 'Fabric' pod 'Crashlytics' pod 'CWStatusBarNotification' pod "ImagePickerSheetController" pod 'KYNavigationProgress' end
  10. 21.

    !

  11. 23.
  12. 24.
  13. 25.
  14. 26.
  15. 27.
  16. 28.
  17. 29.
  18. 30.
  19. 31.
  20. 32.
  21. 37.
  22. 38.
  23. 39.
  24. 40.
  25. 41.
  26. 42.
  27. 43.
  28. 44.

    !

  29. 45.

    !

  30. 47.

    Architectural Approach MODULARIZING YOUR APPS CODE BASES IN LOCAL AND

    MULTIPLATFORM FRAMEWORKS THAT EXPOSE A HOOKABLE INTERFACE.
  31. 49.
  32. 51.
  33. 54.
  34. 56.
  35. 57.
  36. 60.

    mkdir Frameworks; cd Frameworks; pod lib create Core pod lib

    create UI pod lib create Player pod lib create Offline
  37. 62.

    abstract_target 'Frameworks' do pod "Core", :path => "Frameworks/Core" pod "UI",

    :path => "Frameworks/UI" pod "Player", :path => "Frameworks/Player" pod "Offline", :path => "Frameworks/Offline" # Platforms target "MyApp" target "MyTVApp" target "MyWatchApp" end
  38. 65.
  39. 66.
  40. 67.
  41. 68.

    MULTI-PLATFORM FRAMEWORK # Supported platforms SUPPORTED_PLATFORMS = iphoneos iphonesimulator appletvsimulator

    appletvos macosx watchsimulator watchos # Valid architectures VALID_ARCHS[sdk=macosx*] = x86_64 VALID_ARCHS[sdk=iphone*] = arm64 armv7 armv7s # Frameworks Search Path 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
  42. 69.
  43. 70.
  44. 74.
  45. 75.
  46. 77.
  47. 83.
  48. 86.

    MACROS #if !os(macOS) import AppKit typealias Image = NSImage #else

    import UIKit typealias Image = UIImage #end
  49. 88.

    CONCLUSSIONS ▸ Fewer conflicts in big teams. ▸ Easy multiplatfom

    apps. ▸ Aims good practices (API). DO IT IF ONLY IF YOUR PROJECT NEEDS IT
  50. 89.

    REFERENCES ▸ frameworkoriented.io ▸ Building Modern Frameworks ▸ How to

    create a Framework for iOS ▸ Framework vs Library ▸ Static and Dynamic libraries ▸ The Unofficial Guide to xcconfig files
  51. 91.