Non capisco perché sia possibile archiviare le strutture CGPoint
ma non le strutture CLLocationCoordinate2D
. Qual è la differenza per l'archiviatore?NSKeyedArchiver ha esito negativo con le strutture CLLocationCoordinate2D. Perché?
La piattaforma è iOS. Sono in esecuzione nel simulatore e non ho provato sul dispositivo.
// 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" ];
ottengo un incidente al 2 ° archiveRootObject
e questo messaggio viene stampato sulla console:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSKeyedArchiver encodeValueOfObjCType:at:]: this archiver cannot encode structs'
Grazie; questa è la spiegazione perfetta! Lo farò riferimento nel mio rapporto radar :) – TomSwift