April 2017
Intermediate to advanced
316 pages
9h 33m
English
An optional pattern matches values wrapped in a Some(Wrapped)case of an Optional<Wrapped> or ImplicitlyUnwrappedOptional<Wrapped> enumeration. Optional patterns consist of an identifier pattern followed immediately by a question mark and appear in the same places as enumeration case patterns. The following example presents optional pattern matching:
let anOptionalString: String? = nil switch anOptionalString { case let something?: print("\(something)") case nil: print ("None") }
Read now
Unlock full access