所以我有一个名为“Box”的自定义对象,它会为那个对象抛出错误。我的 NSDictionary 里面是......
box = [[Box alloc] initWithHeight:20 height:40];
wrap.dict = [NSMutableDictionary dictionaryWithObjectsAndKeys:numberInt, kInt, numberShort, kShort, numberLong, kLong, numberFloat, kFloat, numberDouble, kDouble, numberBool, kBool, nsString, kString, nsDate, kDate, box, @"keybox", nil];
请注意我在顶部创建并在最后添加到 NSDictionary 中的框对象。在没有盒子之前,一切正常,但是当我添加自定义对象“盒子”时,它无法保存了。
- (void) saveDataToDisk:(NSMutableDictionary *)dictionaryForDisk
{
NSMutableData *data = [NSMutableData data];
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc]initForWritingWithMutableData:data];
//Encode
[archiver setOutputFormat:NSPropertyListBinaryFormat_v1_0];
[archiver encodeObject:dictionaryForDisk forKey:@"Dictionary_Key"];
[archiver finishEncoding];
[data writeToFile:[self pathForDataFile] atomically:YES];
}
- (NSString *) pathForDataFile {
NSArray* documentDir = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString* path = nil;
if (documentDir)
{
path = [documentDir objectAtIndex:0];
}
return [NSString stringWithFormat:@"%@/%@", path, @"data.bin"];
}
这是错误
-[Box encodeWithCoder:]: unrecognized selector sent to instance 0x4e30d60
2011-11-11 11:56:43.430 nike[1186:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Box encodeWithCoder:]: unrecognized selector sent to instance 0x4e30d60'
*** Call stack at first throw:
任何帮助将不胜感激!!!!