【发布时间】:2012-08-30 18:05:31
【问题描述】:
我不明白为什么我可以存档 CGPoint 结构但不能存档 CLLocationCoordinate2D 结构。归档器有什么区别?
平台是 iOS。我在模拟器中运行,还没有在设备上尝试过。
// why does this work:
NSMutableArray *points = [[[NSMutableArray alloc] init] autorelease];
CGPoint p = CGPointMake(10, 11);
[points addObject:[NSValue valueWithBytes: &p objCType: @encode(CGPoint)]];
[NSKeyedArchiver archiveRootObject:points toFile: @"/Volumes/Macintosh HD 2/points.bin" ];
// and this doesnt work:
NSMutableArray *coords = [[[NSMutableArray alloc] init] autorelease];
CLLocationCoordinate2D c = CLLocationCoordinate2DMake(121, 41);
[coords addObject:[NSValue valueWithBytes: &c objCType: @encode(CLLocationCoordinate2D)]];
[NSKeyedArchiver archiveRootObject:coords toFile: @"/Volumes/Macintosh HD 2/coords.bin" ];
我在 2 日遇到了崩溃 archiveRootObject,这条消息被打印到控制台:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSKeyedArchiver encodeValueOfObjCType:at:]: this archiver cannot encode structs'
【问题讨论】:
标签: objective-c ios nskeyedarchiver