2012-05-06 29 views
0

我有一个具有三个属性的实体'testData':time,beat,rate。我需要每次遍历'time'属性,并将相应的节拍和速率值存储在NSMutablearray中。遍历iOS核心数据的单个实体

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(); 
+0

你是什么意思MagicalRecord(一个开源库“穿越时间属性”?你的代码是为了创建一个新的实体,你的问题是关于获取和解析现有的实体。你的问题是什么? – Mundi

回答

0

如果我理解你想要做什么:

做的是实体FetchRequest(无谓语),并把结果放到一个NSArray。

在你回来的数组上做一个ForIn,并将你需要的对象(节拍和速率)添加到它们相应的NSMutableArrays中。

而且 - 你可能想看看这使得处理核心数据有趣多了:)