// - - - - - Verbal Questions - - - - -
//Question #5 - Swift 1.0 or later
//What are the various ways to unwrap an optional? How do they rate in terms of safety?
//Hint: There are at least seven ways.
//Declaration var x:String? = "Test"
//1 Safely unwrapping via binding
if let y = x {
print("x was successfully unwraped and is = \(y)")
}
//x=nil
//2 guard statement
guard let y = x else{
print("x has no value")
fatalError()
}
//3 Force Unwrap
print(x!)
//4 Coalescing nil values
x=nil
var z = x ?? "No value for x"
//5 Implicity unwrapping
var d:String! = "Test2"
//6 Optional chaining
var e = x?.range(of: "Te")
var f = d?.range(of: "Te")
print(e)
print(f)
This tutorial is more than six months old so questions are no longer supported at the moment for it. We will update it as soon as possible. Thank you! :]