2013-09-25 79 views
0

我有一個'動物'模型,它有'name'字符串和'mood'字符串作爲屬性。無論出於何種原因,我想使用核心數據,並且同時希望能夠在用戶想要更新/編輯/註釋該項目時更新屬性'心情'。MagicalRecord中的更新屬性

目前,我有一個帳戶註釋視圖和UITextFields創建一個新條目,並推到陣列,使用

 NSManagedObjectContext *context = [NSManagedObjectContext MR_contextForCurrentThread]; 
    Animal* animal = [Animal MR_createInContext:context]; 
    animal.name = nameField.text; 
    animal.mood = moodField.text; 

    [localContext MR_saveToPersistentStoreWithCompletion:^(BOOL success, NSError *error) { 
     if (!success) { 
      NSLog(@"error"); 
     } 
    }];

,我可以訪問使用

 NSArray* allMyAnimals = [Animal MR_findAll]; 
     if (allMyAccounts.count > 0) { 
      NSInteger animalIndex = allMyAccounts.count; 
      Animal* myAnimal = allMyAnimals[animalIndex - 1]; 
     }

我我的最新註釋想知道,有什麼方法可以更新'情緒'屬性,而不是創建/推送新的模型類?

回答

0

我想我必須退後一步,儘管我發現NSIncrementalStore可能非常適合這項工作或介於兩者之間。