2012-05-06 50 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中。

而且 - 你可能想看看這使得處理核心數據有趣多了:)