I have to store dictionary in core data. I never worked with core data before.
Can anyone help me out that how can I use core data in my existing project and use it to store Dictionary.
I have to store dictionary in core data. I never worked with core data before.
Can anyone help me out that how can I use core data in my existing project and use it to store Dictionary.
NSDictionary into Core Data like that you need to do
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 from Core Data
NSData *data = [[NSMutableData alloc] initWithData:[yourManagedObject valueForKey:@"dictpropertyinmanagedobject"]];
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
NSDictionary *yourDictionary=[[unarchiver decodeObjectForKey:@"dictpropertyinmanagedobject"] retain];
[unarchiver finishDecoding];