chalup / advent-swift

Advent of Code in Swift

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use optional bindings to limit forced unwrapping

ayoy opened this issue · comments

if (noun != nil) { memory[1] = noun! }

A Swifty way to do this would be:

if let validNoun = noun {
    memory[1] = validNoun
}

or even:

if let noun = noun {
    memory[1] = noun // shadowing function parameter is fine in a one-line block
}