I want to save NSMutableDictionary
to NSUserDefaults
then get error:
NSUserDefaults encodeWithCoder unrecognized selector sent to instance. Fatal Exception: NSInvalidArgumentException [NSUserDefaults encodeWithCoder:]: unrecognized selector sent to instance 0x17544a080
Here is my code:
NSUserDefaults *shared2 = [[NSUserDefaults alloc]initWithSuiteName:@"AppGroupName"];
NSMutableData *data1 = [[NSMutableData alloc]init];
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc]initForWritingWithMutableData:data1];
[archiver encodeObject:shareDic forKey: @"shareDic"];
[archiver finishEncoding];
if (data1 !=nil)
{
[shared2 setObject:data1 forKey:@"dicFitnessData"];
}
You need to implement the nscoding protocol.