Tôi không hiểu tại sao tôi có thể lưu trữ cấu trúc CGPoint
nhưng không được cấu trúc CLLocationCoordinate2D
. Sự khác biệt với kho lưu trữ là gì?NSKeyedArchiver không thành công với cấu trúc CLLocationCoordinate2D. Tại sao?
Nền tảng là iOS. Tôi đang chạy trong trình mô phỏng và chưa thử trên thiết bị.
// 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" ];
tôi nhận được một vụ tai nạn vào ngày 2 archiveRootObject
và thông điệp này được in ra cửa sổ Console:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSKeyedArchiver encodeValueOfObjCType:at:]: this archiver cannot encode structs'
Cảm ơn; đó là lời giải thích hoàn hảo! Tôi sẽ tham khảo nó trong báo cáo radar của tôi :) – TomSwift