Optionals
An optional holds a value or nil. Unwrap with if let, guard let, ?? or !.
Example
var s: String? = nil
print(s ?? "none")
s = "hello"
if let t = s { print(t.count) }
print(s?.uppercased() ?? "")Exercise
Default value.
x "none"
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.