[swift-users] Switch based on let

Nate Birkholz nbirkholz at gmail.com
Fri Jul 8 13:00:50 CDT 2016


Much obliged!! This syntax is clean and makes sense once I see it.

Sent from my iPhone, please excuse brevity and errors

> On Jul 8, 2016, at 8:49 AM, Dan Loewenherz via swift-users <swift-users at swift.org> wrote:
> 
>> On Fri, Jul 8, 2016 at 10:34 AM, Roth Michaels via swift-users <swift-users at swift.org> wrote:
>> On Fri, Jul 08 2016 at 11:11:04 AM, Nate Birkholz via swift-users <swift-users at swift.org> wrote:
>> > This gives an error, expecting a colon (:) after object on every case.
>> >
>> > I wanted to be sure I wasn't missing something in my syntax (nor some
>> > obvious-to-others reason this isn't supported) before going to swift
>> > evolution.
>> 
>> There is a bug filed to improve this error message:
>> https://bugs.swift.org/browse/SR-2022
>> 
>> On Fri, Jul 08 2016 at 11:15:48 AM, Dan Loewenherz via swift-users <swift-users at swift.org> wrote:
>> > To my knowledge, you can’t do exactly what you’re trying to do
>> 
>> Here is how:
>> 
>> ```Swift
>> 
>> for object in objects {
>>     switch object {
>>     case let object as Subclass1:
>>         doSomethingWith(object)
>>     case let object as Subclass2:
>>         doSomethingWith(object)
>>     case let object as Subclass3:
>>         doSomethingWith(object)
>>     default:
>>         break
>>     }
>> }
> 
> Beautiful, thanks Roth! This is much nicer. :)
> 
> Dan
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160708/54092385/attachment.html>


More information about the swift-users mailing list