0

time 、beat 、rate の 3 つの属性を持つ単一のエンティティ「testData」があります。毎回「時間」属性をトラバースし、ビートとレートの対応する値をそれぞれの NSMutablearray に格納する必要があります。

NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];
NSEntityDescription *entity = [[self.fetchedResultsController fetchRequest] entity];
NSManagedObject *newManagedObject = [NSEntityDescription insertNewObjectForEntityForName:[entity name] inManagedObjectContext:context];


[newManagedObject setValue:[x] forKey:@"timeStamp"];
[newManagedObject setValue:[y] forKey:@"beat"];
[newManagedObject setValue:[z] forKey:@"rate"];



// Save the context.
NSError *error = nil;
if (![context save:&error]) {
     // Replace this implementation with code to handle the error appropriately.
     // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. 
    NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
    abort();
4

1 に答える 1

0

あなたがやりたいことを私が理解している場合:

そのエンティティ (述語なし) に対して FetchRequest を実行し、結果を NSArray に入れます。

返された配列に対して ForIn を実行し、必要なオブジェクト (ビートとレート) を対応する NSMutableArray に追加します。

また、 MagicalRecord (コア データの処理をより楽しくするオープン ソース ライブラリ) もチェックしてみてください:)

于 2012-05-06T14:35:59.920 に答える