/** * A piece of a class int he PL Swift * Swift is "null-safe"; it cannot have null pointer exceptions * because every variable is either allowed to be null, or * not. On any that is allowed, you must explicitly code to * prevent NPEs. **/ import Foundation class RowerFakerClass: NSObject { var rowerView : RowerView? //? indicated null is allowed var counter : Int = 0 // may not be null var timer = Timer() // type inference func startTimer() { if (!timer.idle()) { //since timer is guaranteed to be non-null can check if it is use without fear self.timer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true, block: { _ in self.sendStroke() }) } } func sendStroke() { counter = counter+1 if let rv = rowerView { // here must confirm that rowerView is not null before using it. // variables created using let are immutable // why is this important here? let rowerData = RowerData(cc: counter, sd: startDate!) rv.notify(data: rowerData) } } }