以下は、NSManagedObject のサブクラスに追加したメソッドを示しています。これは、コア データに個々のエンティティを設定して追加するためのものです。データベースに追加するオブジェクトが約 1000 あります (以下に示すリストではなく、ループで実行しています) パフォーマンスに関する質問です。1000 個のオブジェクトを 1 つずつ追加すると、かなりのオーバーヘッドが追加されますか?コアデータに(そうすると思います)。各管理対象オブジェクトを保存し、それらを単一の (より高速な) 方法で追加する方法はありますか?
NSManagedObjectContext *context = [[self managedDocument] managedObjectContext];
[Atomal createAtomalInContext:context withName:@"H11" age:@57 andType:@"Nantar"];
[Atomal createAtomalInContext:context withName:@"H23" age:@22 andType:@"Nantar"];
[Atomal createAtomalInContext:context withName:@"H54" age:@11 andType:@"Nantar"];
[Atomal createAtomalInContext:context withName:@"H34" age:@98 andType:@"Nantar"];
[Atomal createAtomalInContext:context withName:@"H17" age:@35 andType:@"Nantar"];
.
+ (Atomal *)createAtomalInContext:(NSManagedObjectContext *)context withName:(NSString *)name age:(NSNumber *)age andType:(NSString *)type {
Atomal *atomal = nil;
atomal = [NSEntityDescription insertNewObjectForEntityForName:@"Atomal" inManagedObjectContext:context];
// POPULATE PROPERTIES
[atomal setName:name];
[atomal setAge:age];
[atomal setType:type];
NSLog(@"CORE: Adding >>> %@ %@ %@", [atomal name], [atomal age], [atomal type]);
return atomal;
}