Slide 1

Slide 1 text

PROTOCOLS ALL THE WAY DOWN DOT SWIFT | PARIS, FRANCE | JANUARY 2018 @DESIGNATEDNERD | BAKKENBAECK.COM | JUSTHUM.COM

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

PROTOCOL-ORIENTED PROGRAMMING

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

PROTOCOL-ORIENTED PROGRAMMING

Slide 7

Slide 7 text

PROTOCOLS WITH DEFAULT IMPLEMENTATIONS

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

DEFAULT PROTOCOL IMPLEMENTATION extension

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

No content

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

CONDITIONAL DEFAULT PROTOCOL IMPLEMENTATION extension

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

No content

Slide 31

Slide 31 text

extension

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

where Self:...

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

github.com/designatednerd/ ProtocolPlayground

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

MULTIPLE where CLAUSES

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

No content

Slide 51

Slide 51 text

No content

Slide 52

Slide 52 text

No content

Slide 53

Slide 53 text

No content

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

No content

Slide 56

Slide 56 text

No content

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

No content

Slide 59

Slide 59 text

SUBCLASS-LIKE BEHAVIOR WITHOUT THE BAGGAGE OF SUBCLASSING

Slide 60

Slide 60 text

CENTRALIZATION! DRY CODE!

Slide 61

Slide 61 text

NO INSANE INHERITANCE TREES

Slide 62

Slide 62 text

PROTOCOL-ORIENTED ! PITFALLS

Slide 63

Slide 63 text

POP QUIZ

Slide 64

Slide 64 text

No content

Slide 65

Slide 65 text

No content

Slide 66

Slide 66 text

No content

Slide 67

Slide 67 text

No content

Slide 68

Slide 68 text

No content

Slide 69

Slide 69 text

No content

Slide 70

Slide 70 text

No content

Slide 71

Slide 71 text

No content

Slide 72

Slide 72 text

TYPE INFERENCE: !

Slide 73

Slide 73 text

TYPE INFERENCE: !

Slide 74

Slide 74 text

TYPE INFERENCE: !

Slide 75

Slide 75 text

SPECIFYING PROTOCOL TYPE: !

Slide 76

Slide 76 text

SPECIFYING PROTOCOL TYPE: !

Slide 77

Slide 77 text

SPECIFYING PROTOCOL TYPE: !

Slide 78

Slide 78 text

SPECIFYING PROTOCOL TYPE: !

Slide 79

Slide 79 text

SPECIFYING PROTOCOL TYPE: !

Slide 80

Slide 80 text

No content

Slide 81

Slide 81 text

No content

Slide 82

Slide 82 text

No content

Slide 83

Slide 83 text

DEFAULT IMPLEMENTATIONS VS. EXTENSIONS VS. SUBCLASSES

Slide 84

Slide 84 text

DEFAULT IMPLEMENTATIONS **(PLAIN VANILLA OR CONDITIONAL) VS. EXTENSIONS VS. SUBCLASSES

Slide 85

Slide 85 text

> Do I need this to work on all instances and/or subclasses of a particular thing? Extension! > Do I need this method to work only when I say it should, or in a particular combination of circumstances? Default implementation! > Does this always need to be called from a particular lifecycle or delegate method? Subclass!

Slide 86

Slide 86 text

CHOOSE YOUR TOOLS WISELY

Slide 87

Slide 87 text

No content

Slide 88

Slide 88 text

! MERÇI BEAUCOUP! !

Slide 89

Slide 89 text

LINKS! > Protocol-Oriented Programming, WWDC 2015 developer.apple.com/videos/play/wwdc2015/408 > The ghost of Swift Bugs Future, Alexandros Salazar nomothetis.svbtle.com/the-ghost-of-swift-bugs- future

Slide 90

Slide 90 text

PHOTO CREDITS! > Businessman, by Daniel X. O'Neil flickr.com/photos/juggernautco/6037175371 > Hammered Screw, by Justin Baeder flickr.com/photos/justinbaeder/5317820857 > Knot, by JP Davidson flickr.com/photos/jpdavidsonimages/4677642617