-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
for_where with single if for enumed enumerated array #1968
Comments
In your case you could just use |
Hi.
Sure, this works fine for this case. But when we add some associated value like |
Agree, this is a bug, but the sample shared in the first comment isn't why. Here's a sample that can't be changed to using a enum Value {
case valueA, valueB(a: Int)
}
func firstIndexOfValueB(in array: [Value]) -> Int? {
for (index, value) in array.enumerated() { // `for_where` with single `if` warning here
if case .valueB(_) = value {
return index
}
}
return nil
} |
I think this change was not necessary and should be undone. This is not a bug as the example can be changed to: enum Value {
case valueA, valueB(a: Int)
}
func firstIndexOfValueB(in array: [Value]) -> Int? {
for case let (index, .valueB) in array.enumerated() {
return index
}
return nil
} Pattern matching also works in for loops. |
New Issue Checklist
Bug Report
When i try to enumerate array that contains enum values and find the index of some one with single
if
, swiftlint shows mefor_where violation with single if
warning. Probably for this situation there should be no warning?The text was updated successfully, but these errors were encountered: