تخطَّ إلى المحتوى

First On Possibly Empty (ARCH9078)

هذا المحتوى غير متوفر بلغتك بعد.

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.

let u = users.filter { $0.active }.first!
guard let u = users.first(where: { $0.active }) else { return }

Use first(where:) and handle nil.