• 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: Noob Swift frustration with dicts and optionals
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Noob Swift frustration with dicts and optionals


  • Subject: Re: Noob Swift frustration with dicts and optionals
  • From: Jens Alfke <email@hidden>
  • Date: Wed, 17 Sep 2014 12:55:30 -0700


On Sep 17, 2014, at 10:34 AM, Marco S Hyman <email@hidden> wrote:

Get rid of the ? after dict["foo"].  It is not necessary.  Yes,
the return value is an optional.  That's fine.

Yeah, I get that; but my assumption was that the "as? String" _expression_ represented a dereference of the value, so I'd need to unwrap it before that evaluated. It sounds like what really happens is that the "as?" operator knows about optionals and will evaluate to nil if the LHS is nil.

The message still seems wrong, though: the operand of the "?" is the dict lookup, which _is_ optional.

now generates the error 'String' is not a subtype of '(NSObject, AnyObject)' which goes to show that String and NSString aren't as equivalent as one would hope.

Yeah, so my interpretation is that this is a bug in either the compiler or the class library. The docs say String and NSString are equivalent. And the fact that the error message involves some hidden(?) intermediate type makes this seem unintentional. I'll file a bug report.

—Jens
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Noob Swift frustration with dicts and optionals
      • From: Marco S Hyman <email@hidden>
    • Re: Noob Swift frustration with dicts and optionals
      • From: Roland King <email@hidden>
References: 
 >Noob Swift frustration with dicts and optionals (From: Jens Alfke <email@hidden>)
 >Re: Noob Swift frustration with dicts and optionals (From: Marco S Hyman <email@hidden>)

  • Prev by Date: Re: Docs?
  • Next by Date: Re: Docs?
  • Previous by thread: Re: Noob Swift frustration with dicts and optionals
  • Next by thread: Re: Noob Swift frustration with dicts and optionals
  • Index(es):
    • Date
    • Thread