Framework Oriented Programming - Mobilization.pl

Framework Oriented Programming - Mobilization.pl

B0a336761194918a853deeff1f22b537?s=128

Pedro Piñera Buendía

October 22, 2016
Tweet

Transcript

  1. Framework Oriented Programming @pepibumur / pepibumur@gmail.com

  2. Hi! ! Pedro iOS Developer at SoundCloud @pepibumur Twitter/GitHub www.ppinera.es

  3. Context Motivation How Questions Downsides

  4. None
  5. Things with something in common

  6. !"#

  7. None
  8. None
  9. Boxes Frameworks

  10. 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
  11. External Frameworks

  12. None
  13. 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
  14. ! 1 app target + X External frameworks

  15. Simple projects

  16. Small teams (and not distributed)

  17. Only 1-2 platforms ! "

  18. !

  19. New platforms !"⌚$

  20. None
  21. None
  22. None
  23. None
  24. None
  25. None
  26. None
  27. None
  28. None
  29. None
  30. Simple complex projects

  31. Couldn't reuse code scale easily

  32. Bigger projects Bigger teams (and also distributed)

  33. Conflicts Between teams (Interdependencies)

  34. None
  35. None
  36. None
  37. None
  38. None
  39. None
  40. None
  41. !

  42. !

  43. Framework Oriented Programming

  44. Architectural Approach Modularizing your apps code bases in local and

    multiplatform frameworks that expose a hookable interface.
  45. New platforms/targets Gluing

  46. None
  47. Atomic teams that own frameworks

  48. None
  49. Decide about persistence Decide about patterns Decide about architecture Decide

    about language
  50. None
  51. Framework Exposes an API

  52. None
  53. Fewer interdependencies Fewer conflicts Fewer bugs

  54. None
  55. None
  56. How to Setup the project

  57. Using CocoaPods Create pods Link the project against them

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

    create UI pod lib create Player pod lib create Offline
  59. Pod::Spec.new do |s| s.name = 'Player' s.dependency 'Core' s.dependency 'UI'

    end
  60. 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
  61. Manually Creating/Linking

  62. Workspace Multiple framework projects Linked/Embedded

  63. None
  64. None
  65. None
  66. 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
  67. None
  68. Pandora github.com/frameworkoriented/pandora gem install pandora-frameworks pandora create Core org.myorg

  69. Questions With answers

  70. External dependencies? » Minimize them (DIY) » Most dependent framework,

    fewer dependencies.
  71. CocoaPods/Carthage? » Up to you » Both support local/external dependencies.

    » Depends on your setup.
  72. Static/Dyamic? » Linking: » Static: Compilation time. » Dynamic: Startup

    time. » Swift only supports dynamic.
  73. Linking/Embedding? » Linking "connects" dependencies. » Embedding "copies" them to

    the target (app)
  74. Analyze Existing tools (e.g. CocoaPods) » Reverse engineering.

  75. None
  76. None
  77. Transitioning from Monolithic? » Start pulling tooling: » API client.

    » Database wrapper. » Analytics. » Logging » Continue gradually pulling features from the least dependent.
  78. How many frameworks? » It depends on your setup »

    Find the stack that works for you.
  79. Freelance Setup

  80. Feature Teams Setup

  81. Multi-Platform Setup

  82. One/Multiple repositories? » One repository » Unless: » Other repository

    needs a framework. » You make a framework open source.
  83. Versioning? » Unified versioning. » Unless different repositories. » Very

    useful: deprecation macros.
  84. Public/Internal/Private? » Internal by default. » Public API. » Restrictive

    over permissive. » Enforce good practices.
  85. Downsides

  86. Documentation Not good enough

  87. No homogeneity In APIs

  88. Macros #if !os(macOS) import AppKit typealias Image = NSImage #else

    import UIKit typealias Image = UIImage #end
  89. Xcode Has a long way to go ! "

  90. Conclussions » Fewer conflicts in big teams. » Easy multiplatfom

    apps. » Aims good practices (API). Do it if only if your project needs it
  91. 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
  92. Thanks Questions? #yatusabes ! @pepibumur / pepibumur@gmail.com Photos from Unsplash

    Slides bit.ly/frameworkoriented
  93. None