[英]Core Data Transformable Attribute
我正在嘗試訪問可轉換核心數據對象的屬性,如下所示:
MainObject *localObject = [self.myArray objectAtIndex:indexPath.row];
TransformableObject *actualObject = localObject.transformableObject;
這很好。 我NSLog
actualObject
並獲取正確的鍵/值對:
actualObject:{
property = "Foo";
property2 = "Apple";
}
但是,當II嘗試執行以下操作:
NSLog (@"property:%@",actualObject.property)
我得到-[__NSCFDictionary property]: unrecognized selector sent to instance
我究竟做錯了什么? 在我的核心數據類中,我有:
@interface MainObject : NSManagedObject
@property (nonatomic, retain) TransformableObjectClass *transformableObject;
編輯:這是我在核心數據中設置對象的方式
MainObject *event = (MainObject *)[NSEntityDescription insertNewObjectForEntityForName:@"MainObject" inManagedObjectContext:[AppDelegateMy managedObjectContext]];
[event setValuesForKeysWithDictionary:[myArrray objectAtIndex:i]];
-setValuesForKeysWithDictionary:
和Core Data都沒有足夠神奇的功能來完成這項工作,而無需您付出更多的努力。 現在,您只是在JSON響應中將字典分配給新的托管對象的transformableObject
屬性。 如果您嘗試保存上下文,我想它可能會失敗。 如果要將這些詞典轉換為實際的TransformableObjectClass
實例,則需要自己進行操作。
如果您的應用程序中包含大量此類內容,則可能需要研究RestKit或其他類似ClassMapper的其他開源JSON到對象映射庫。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.