What does this print?
func double(_ n: Int?) -> Int {
guard let n else { return -1 }
return n * 2
}
print(double(7))
print(double(nil))
Try it in the online Swift Playground →
[spoiler title="Solution"]
Answer:
14 -1
Explanation:
guard exits early when the value is nil. The first call doubles 7, the second returns -1.
[/spoiler]