Re: Implicitly unwrapped optionals
Re: Implicitly unwrapped optionals
- Subject: Re: Implicitly unwrapped optionals
- From: Vincent <email@hidden>
- Date: Sun, 15 Jun 2014 10:34:22 +0200
>
> Did you mean “implicitly unwrapped”? Then, by the above logic, the type of the ‘if’ expression is Bool, so it would crash if ‘bbb’ is nil. Otherwise, it would test the boolean value of ‘bbb’.
Turns out, after a try in a playground, that this is the right way to do it:
var b : Bool! = nil
var ans : String?
if b {
if b! {
ans = "True"
} else {
ans = "False"
}
} else {
ans = "Nil"
}
The first test sifts nil from everything else, and the second one 'true' from 'false'.
Vincent
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden