我必须将字典存储在核心数据中。我以前从未使用过核心数据。将NSDictionary保存在coreData中
任何人都可以帮助我,我怎样才能在我现有的项目中使用核心数据,并用它来存储Dictionary。
我必须将字典存储在核心数据中。我以前从未使用过核心数据。将NSDictionary保存在coreData中
任何人都可以帮助我,我怎样才能在我现有的项目中使用核心数据,并用它来存储Dictionary。
的NSDictionary到核心数据一样,你需要一些谷歌我了解,我必须做的归档和取消后做
NSMutableData *data = [[NSMutableData alloc] init];
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
[archiver encodeObject:yourDictionary forKey:@"dictpropertyinmanagedobject"];
[archiver finishEncoding];
[archiver release];
[self.managedObject setValue:data forKey:@"dictpropertyinmanagedobject"];
的NSDictionary从核心数据
NSData *data = [[NSMutableData alloc] initWithData:[yourManagedObject valueForKey:@"dictpropertyinmanagedobject"]];
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
NSDictionary *yourDictionary=[[unarchiver decodeObjectForKey:@"dictpropertyinmanagedobject"] retain];
[unarchiver finishDecoding];
我可以在任何类中定义self.managedObject。 –
看看这个http://stackoverflow.com/questions/8682324/insert-nsdictionary-into-coredata – Sport
- 为此做好准备。但我不知道如何在项目中实现它。 –
你见过[THIS](http://stackoverflow.com/questions/22211633/core-data-not-saving-transformable-nsmutabledictionary) –
检出:[将NSDictionary插入CoreData](http://stackoverflow.com/questions/8682324/insert-nsdictionary-into-coredata) – Amar