Slide 1

Slide 1 text

Framework Oriented Programming @pepibumur / [email protected]

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

Context Motivation How Questions Downsides

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

Things with something in common

Slide 6

Slide 6 text

!"#

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

Boxes Frameworks

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

External Frameworks

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

! 1 app target + X External frameworks

Slide 15

Slide 15 text

Simple projects

Slide 16

Slide 16 text

Small teams (and not distributed)

Slide 17

Slide 17 text

Only 1-2 platforms ! "

Slide 18

Slide 18 text

!

Slide 19

Slide 19 text

New platforms !"⌚$

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

Simple complex projects

Slide 31

Slide 31 text

Couldn't reuse code scale easily

Slide 32

Slide 32 text

Bigger projects Bigger teams (and also distributed)

Slide 33

Slide 33 text

Conflicts Between teams (Interdependencies)

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

!

Slide 42

Slide 42 text

!

Slide 43

Slide 43 text

Framework Oriented Programming

Slide 44

Slide 44 text

Architectural Approach Modularizing your apps code bases in local and multiplatform frameworks that expose a hookable interface.

Slide 45

Slide 45 text

New platforms/targets Gluing

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

Atomic teams that own frameworks

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

Decide about persistence Decide about patterns Decide about architecture Decide about language

Slide 50

Slide 50 text

No content

Slide 51

Slide 51 text

Framework Exposes an API

Slide 52

Slide 52 text

No content

Slide 53

Slide 53 text

Fewer interdependencies Fewer conflicts Fewer bugs

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

No content

Slide 56

Slide 56 text

How to Setup the project

Slide 57

Slide 57 text

Using CocoaPods Create pods Link the project against them

Slide 58

Slide 58 text

mkdir Frameworks; cd Frameworks; pod lib create Core pod lib create UI pod lib create Player pod lib create Offline

Slide 59

Slide 59 text

Pod::Spec.new do |s| s.name = 'Player' s.dependency 'Core' s.dependency 'UI' end

Slide 60

Slide 60 text

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

Slide 61

Slide 61 text

Manually Creating/Linking

Slide 62

Slide 62 text

Workspace Multiple framework projects Linked/Embedded

Slide 63

Slide 63 text

No content

Slide 64

Slide 64 text

No content

Slide 65

Slide 65 text

No content

Slide 66

Slide 66 text

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

Slide 67

Slide 67 text

No content

Slide 68

Slide 68 text

Pandora github.com/frameworkoriented/pandora gem install pandora-frameworks pandora create Core org.myorg

Slide 69

Slide 69 text

Questions With answers

Slide 70

Slide 70 text

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

Slide 71

Slide 71 text

CocoaPods/Carthage? » Up to you » Both support local/external dependencies. » Depends on your setup.

Slide 72

Slide 72 text

Static/Dyamic? » Linking: » Static: Compilation time. » Dynamic: Startup time. » Swift only supports dynamic.

Slide 73

Slide 73 text

Linking/Embedding? » Linking "connects" dependencies. » Embedding "copies" them to the target (app)

Slide 74

Slide 74 text

Analyze Existing tools (e.g. CocoaPods) » Reverse engineering.

Slide 75

Slide 75 text

No content

Slide 76

Slide 76 text

No content

Slide 77

Slide 77 text

Transitioning from Monolithic? » Start pulling tooling: » API client. » Database wrapper. » Analytics. » Logging » Continue gradually pulling features from the least dependent.

Slide 78

Slide 78 text

How many frameworks? » It depends on your setup » Find the stack that works for you.

Slide 79

Slide 79 text

Freelance Setup

Slide 80

Slide 80 text

Feature Teams Setup

Slide 81

Slide 81 text

Multi-Platform Setup

Slide 82

Slide 82 text

One/Multiple repositories? » One repository » Unless: » Other repository needs a framework. » You make a framework open source.

Slide 83

Slide 83 text

Versioning? » Unified versioning. » Unless different repositories. » Very useful: deprecation macros.

Slide 84

Slide 84 text

Public/Internal/Private? » Internal by default. » Public API. » Restrictive over permissive. » Enforce good practices.

Slide 85

Slide 85 text

Downsides

Slide 86

Slide 86 text

Documentation Not good enough

Slide 87

Slide 87 text

No homogeneity In APIs

Slide 88

Slide 88 text

Macros #if !os(macOS) import AppKit typealias Image = NSImage #else import UIKit typealias Image = UIImage #end

Slide 89

Slide 89 text

Xcode Has a long way to go ! "

Slide 90

Slide 90 text

Conclussions » Fewer conflicts in big teams. » Easy multiplatfom apps. » Aims good practices (API). Do it if only if your project needs it

Slide 91

Slide 91 text

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

Slide 92

Slide 92 text

Thanks Questions? #yatusabes ! @pepibumur / [email protected] Photos from Unsplash Slides bit.ly/frameworkoriented

Slide 93

Slide 93 text

No content