[swift-users] Switch based on let

Roth Michaels roth at rothmichaels.us
Fri Jul 8 10:34:02 CDT 2016


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
    }
}

```

-- 
Roth Michaels
roth at rothmichaels.us



More information about the swift-users mailing list