2014-07-15 22 views
0

我知道這應該是可能的,但我無法找到正確的API來執行此操作。動態設置核心數據鍵/值對

可以說我有在給定的實體的屬性:

  • ATR1
  • ATR2
  • ATR3

我想 「動態」 設置屬性。例如,如果我有下面的代碼塊:

NSString *attributeToSet = @"atr2" 
int newValue = 3 

有一些調用,比如:

[NSManagedObject setAttribute:attributeToSet newValue:newValue] 

謝謝!

回答

0

查看爲默認主/細節類型的應用程序生成的模板代碼。它包含以下代碼示例:

// Normally you should use accessor methods, but using KVC here avoids the need to add a custom class to the template. 
[newManagedObject setValue:[NSDate date] forKey:@"timeStamp"]; 

key對應於您定義的實體屬性。

+0

我會試試看。謝謝! – Jeef