NSManagedObject *InsertChefAndSave(NSError **error) {
NSManagedObject *chef = nil;
chef = [NSEntityDescription insertNewObjectForEntityForName:@"Chef" inManagedObjectContext:context];
[chef setValue:@"John" forKey:@"firstName"];
[chef setValue:@"Doe" forKey:@"lastName"];
if ([context save:error] == NO) {
[context deleteObject:chef];
chef = nil;
}
return chef;
}
- あらかじめ取得してあるデータベースのコンテキストとエンティティ(テーブル)の名前を指定してレコードを入れる準備をする
- etValue: forKey:でレコードのデータを設定する(keyはプロパティ(フィールド)の名前)
- コンテキストに対しsaveのメッセージを送る