在我的应用程序中,我将 myObject 归档到 NSData,然后取消归档 NSData 以获取 myObject。崩溃跟踪
0 CoreFoundation 0x2fe9ef46 __exceptionPreprocess + 126
1 libobjc.A.dylib 0x3a1b36aa objc_exception_throw + 34
2 CoreFoundation 0x2fe9ee88 +[NSException raise:format:] + 100
3 Foundation 0x30815098 -[NSKeyedUnarchiver initForReadingWithData:] + 2464
4 Foundation 0x30814680 +[NSKeyedUnarchiver unarchiveObjectWithData:] + 48
MyObject 包含以下属性:
@property (nonatomic,strong) NSData * imageData;
@property (nonatomic,strong) NSData * thumbnailData;
@property (nonatomic,strong) NSString * imagePath;
@property (nonatomic,strong) NSString * thumnailPath;
@property (nonatomic,strong) NSString * documentIdentifier;
@property (nonatomic,strong) NSString *paperIdentifier;
当尝试 Unarchive NSData 时发生此崩溃。
NSData ==> OS_dispatch_data(138693 字节)。
我使用 [NSKeyedUnarchiver unarchiveObjectWithData:documentData] 来取消归档并在 myobject 类中实现这些方法:
- (void)encodeWithCoder:(NSCoder *)coder
{
[coder encodeObject:self.imageData forKey:IMAGE_DATA_KEY];
[coder encodeObject:self.thumbnailData forKey:THUMBNAIL_DATA_KEY];
[coder encodeObject:self.imagePath forKey:IMAGE_PATH_KEY];
[coder encodeObject:self.thumnailPath forKey:THUMNBAIL_PATH_KEY];
[coder encodeObject:self.paperIdentifier forKey:PAPER_ID_KEY];
[coder encodeObject:self.documentIdentifier forKey:DOCUMENT_ID_KEY];
}
- (id)initWithCoder:(NSCoder *)coder
{
self = [super init];
if (self) {
self.imageData = [coder decodeObjectForKey:IMAGE_DATA_KEY];
self.thumbnailData = [coder decodeObjectForKey:THUMBNAIL_DATA_KEY];
self.imagePath = [coder decodeObjectForKey:IMAGE_PATH_KEY];
self.thumnailPath = [coder decodeObjectForKey:THUMNBAIL_PATH_KEY];
self.paperIdentifier = [coder decodeObjectForKey:PAPER_ID_KEY];
self.documentIdentifier = [coder decodeObjectForKey:DOCUMENT_ID_KEY];
}
return self;
}
任何人都可以帮助我吗?