Swiftlint warning : For Where Violation: `where` clauses are preferred over a single `if` inside a `for`. (for_where)
The syntax preferred by your swiftlint configuration is:
for settingsKeys in searchResults where settingsKeys.key == settingsObject.key {
settingsKeys.value = settingsObject.value
try context.save()
}
Which is the similar to
for settingsKeys in (searchResults.filter { $0.key == settingsObject.key }) {
settingsKeys.value = settingsObject.value
try context.save()
}
If you know there is only one result with the same key
, you might directly use
if let settingsKeys = (searchResults.first { $0.key == settingsObject.key }) {
settingsKeys.value = settingsObject.value
try context.save()
}
Looks like it's expecting the where
to be part of the for
…
for settingsKeys in searchResults where settingsKeys.key == settingsObject.key {
settingsKeys.value = settingsObject.value
try context.save()
}