Other answers show how to solve your problem, but don't really explain why this error occurs, so I thought I could do it.
guard let ... else, if let ..., --- , nil --- ;
var a: Int? = 5
if let b = a {
// b unwrapped, type inferred to non-optional type Int
print(b) // "5"
}
, a nil, b ( ) Int, nil.
b , , a . b , " " a (Int?) b (Int?), , , if let ... - .
a = nil
if let b: Int! = a {
print(b)
print(b.dynamicType)
let c: Int! = nil
print(c.dynamicType)
}
if let b: Int? = a {
print(b)
}
, , b Int? () Int! ( ), b, if let ( Int?). , event (event!.iconImgData) guard let, .
, guard let ... else , eventsImagesLoading.removeValueForKey(location) nil, event ( Event!) nil .
func foo() {
let bar : Int? = nil
guard let _: Int! = bar else {
print("this is surely nil")
return
}
print("but an implicitly unwrapped optional will fall through")
}
foo()
, ( nil ). nil ( : nil).
, , , , guard let INFER_THIS = ... else if let INFER_THIS = ....
, ( ), .