No entiendo por qué puedo archivar las estructuras de CGPoint
pero no CLLocationCoordinate2D
structs. ¿Cuál es la diferencia para el archivador?NSKeyedArchiver falla con CLLocationCoordinate2D structs. ¿Por qué?
La plataforma es iOS. Estoy corriendo en el simulador y no lo he probado en el 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" ];
me sale un accidente en la segunda archiveRootObject
y este mensaje se imprime en la consola:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSKeyedArchiver encodeValueOfObjCType:at:]: this archiver cannot encode structs'
Gracias; esa es la explicación perfecta! Lo haré referencia en mi informe de radar :) – TomSwift