First On Possibly Empty (ARCH9078)
Ce contenu n’est pas encore disponible dans votre langue.
Key swift.performance.first-on-possibly-empty · Severity warning · Category performance
Flags .first! / .last! / [0] on a filtered or fetched collection with no emptiness guard.
Incorrect
Section titled “Incorrect”let u = users.filter { $0.active }.first!Correct
Section titled “Correct”guard let u = users.first(where: { $0.active }) else { return }Use first(where:) and handle nil.