DEV Community

Dawn Song
Dawn Song

Posted on

Answer: Type casting in for-in loop

For Swift 2 and later:

Swift 2 adds case patterns to for loops, which makes it even easier and safer to type cast in a for loop:

for case let button as AClass in view.subviews {
    // do something with button
}

Why is this better than what you could…

Top comments (0)