The “line” var in this function seems to magically appear without being declared anywhere… meaning I’m probably confused about something.
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
if var line = currentLine {
let touch = touches.first!
let location = touch.location(in: self)
line.end = location
finishedLines.append(line)
}
currentLine = nil
setNeedsDisplay()
}
The DrawView class has a global “currentLine” var, but nothing for “line.” So what am I missing? (And thanks in advance!)
Edit to add: I think what’s confusing me is that I’m used to “if let” statements, but I haven’t seen “if var” before. So it’s making a little more sense now… but I’m not yet clear on why “if let” couldn’t have been used instead.