"line" var in "override func touchesEnded" -- where is it coming from?

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.

OK, answering my own question…

The “line” has to be a var because within the if statement, we’re going to modify “line.end,” which wouldn’t be possible if “line” were a constant.

Makes sense, and I was mainly thrown off by the new-to-me “if var” construction.