Slide 1

Slide 1 text

@gregheo AltConf, June 2018 Shared Mutable State !

Slide 2

Slide 2 text

@gregheo AltConf, June 2018 State

Slide 3

Slide 3 text

@gregheo AltConf, June 2018 Exclusive Shared Immutable Mutable

Slide 4

Slide 4 text

@gregheo AltConf, June 2018 Make it difficult
 to get wrong

Slide 5

Slide 5 text

@gregheo AltConf, June 2018 "

Slide 6

Slide 6 text

@gregheo AltConf, June 2018 queue1.async {
 
 } queue2.async {
 
 
 } 
 stuff()
 
 things()
 things2()


Slide 7

Slide 7 text

@gregheo AltConf, June 2018 Exclusive Shared Immutable Mutable private let private var
 private queue UIDevice
 Screen size &

Slide 8

Slide 8 text

@gregheo AltConf, June 2018 Fewer entry points

Slide 9

Slide 9 text

@gregheo AltConf, June 2018 internal
 private
 fileprivate

Slide 10

Slide 10 text

@gregheo AltConf, June 2018 Pass in values

Slide 11

Slide 11 text

@gregheo AltConf, June 2018 class Printer { var num: Int func print() { print(num) } }

Slide 12

Slide 12 text

@gregheo AltConf, June 2018 func printNum(num: Int) { print(num) }

Slide 13

Slide 13 text

@gregheo AltConf, June 2018 Who enqueues
 the queues?

Slide 14

Slide 14 text

@gregheo AltConf, June 2018 
 // call from anywhere!
 public func something() {
 privateQueue.sync { … } }


Slide 15

Slide 15 text

@gregheo AltConf, June 2018 Queue Callback

Slide 16

Slide 16 text

@gregheo AltConf, June 2018 
 // always call on the main queue!
 public func something() 


Slide 17

Slide 17 text

@gregheo AltConf, June 2018 
 // always call on the main queue!
 public func something() {
 dispatchPrecondition(condition: .onQueue(.main))
 }


Slide 18

Slide 18 text

@gregheo AltConf, June 2018 # Do I have order right? Is the order even knowable? Is it concurrent?

Slide 19

Slide 19 text

@gregheo AltConf, June 2018 $ Too much access Mutable variables Thread uncertainty

Slide 20

Slide 20 text

@gregheo AltConf, June 2018 ✅ “Limit access “Functional” approach “Private queues

Slide 21

Slide 21 text

@gregheo AltConf, June 2018 # $ ✅

Slide 22

Slide 22 text

@gregheo AltConf, June 2018 Make it difficult
 to get wrong