• Works side by side with Objective-C code • Single implementation file • Error handling, closures, multiple return values, functional programming patterns, generics, fast iteration etc. etc. etc.
or Objective-C. The nearest thing in Objective-C is the ability to return nil • However, this only works for objects - it doesn’t work for structures, basic C types, or enumeration values. Requires NSNotFound or something. • Optionals in Swift work for everything
: Int? = cast["vader"] if let vader = cast["vader"] { // Optional Binding } guard let vader = cast["vader"] else { break } var vader2: Int = cast["vader"]!
let (statusCode, statusMessage) = http404Error print("The status code is \(statusCode)") // prints "The status code is 404" print("The status message is \(statusMessage)") // prints "The status message is Not Found”
code is \(http200Status.statusCode)") // prints "The status code is 200" print("The status message is \(http200Status.description)") // prints "The status message is OK
conditions your program may encounter during execution • Determine the underlying cause of failure unlike optionals which only communicate the presence of a failure