• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Implicitly unwrapped optionals
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Implicitly unwrapped optionals (From: Roland King <email@hidden>)
 >Re: Implicitly unwrapped optionals (From: Ken Thomases <email@hidden>)
 >Re: Implicitly unwrapped optionals (From: Quincey Morris <email@hidden>)

  • Prev by Date: Re: title bar hit test?
  • Next by Date: Re: title bar hit test?
  • Previous by thread: Re: Implicitly unwrapped optionals
  • Next by thread: title bar hit test?
  • Index(es):
    • Date
    • Thread