Skip to content

Count Vs Exists (ARCH9063)

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.

if try context.fetch(request).isEmpty
request.fetchLimit = 1
if try context.count(for: request) == 0

Use count(for:) with fetchLimit = 1.