Count Vs Exists (ARCH9063)
Ce contenu n’est pas encore disponible dans votre langue.
Key swift.orm.count-vs-exists · Severity info · Category orm
Flags context.fetch(request).count / .isEmpty used only to test presence - count(for:) with fetchLimit = 1 stops at the first row.
Incorrect
Section titled “Incorrect”if try context.fetch(request).isEmptyCorrect
Section titled “Correct”request.fetchLimit = 1if try context.count(for: request) == 0Use count(for:) with fetchLimit = 1.