Re: Any way to combine for and if-let?
Re: Any way to combine for and if-let?
- Subject: Re: Any way to combine for and if-let?
- From: Rick Mann <email@hidden>
- Date: Tue, 07 Jul 2015 17:30:15 -0700
Thanks. I was looking at the Swift reference. The docs seem to be incorrect:
https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Patterns.html#//apple_ref/swift/grammar/pattern
"There are two type-casting patterns, the is pattern and the as pattern. Both type-casting patterns appear only in switch statement case labels."
> On Jul 7, 2015, at 17:26 , Quincey Morris <email@hidden> wrote:
>
> On Jul 7, 2015, at 16:58 , Rick Mann <email@hidden> wrote:
>>
>> Also, the enumerator is a NSDirectoryEnumerator. It returns AnyObject type, so wouldn't there have to be an NSURL cast in there somewhere?
>
> Try:
>
>> for case let url as NSURL in enumerator
>
> The way to figure these things out is to start with a switch statement, where the patterns are a bit more intuitive, or at least better documented:
>
>> switch anyObject {
>> case let url as NSURL:
>> …
>> }
>
> and the case is what you drop into the “for … in enumerator” statement.
>
--
Rick Mann
email@hidden
_______________________________________________
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