Re: Noob Swift frustration with dicts and optionals
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