Aller au contenu

Insert Loop Without Batch (ARCH9053)

Ce contenu n’est pas encore disponible dans votre langue.

Key swift.orm.insert-loop-without-batch · Severity warning · Category orm

Flags NSEntityDescription.insertNewObject / realm.add inside a loop - one managed object per row where NSBatchInsertRequest exists.

for row in rows { NSEntityDescription.insertNewObject(forEntityName: "Order", into: context) }
let batch = NSBatchInsertRequest(entityName: "Order", objects: rows)

Use NSBatchInsertRequest (Core Data) or realm.add(objects) in one write.