1

Is it possible to enumerate an array of Enum cases with contained values while filtering them in the same line?

Right now I'm doing

let modes = [FilterMode]()
for mode in modes {
    if case .categories(let data) = mode {}
}

What I'd like to do is something like this

for mode in modes where case .categories(let data) = mode {}

Or something like that. Is that currently possible in Swift 3?

1 Answer 1

3

You cannot use pattern matching in the where clause, but you can use for with a case pattern (since Swift 2):

for case .categories(let data) in modes {
    // ... use `data` ...
}

This can also be written as

for case let .categories(data) in modes { ... }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.