views:

241

answers:

1

How do I archive an array of NSValues ? What conversions should I make to do this? It won't archive it as is.

Code:

[[NSUserDefaults standardUserDefaults] setObject:[NSKeyedArchiver 
archivedDataWithRootObject:[[NSArray alloc] initWithArray:drawingsArray]] 
forKey:@"NSValuesArray"];

Error:

 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSKeyedArchiver encodeValueOfObjCType:at:]: this archiver cannot encode structs'

Array Data:

drawingsArray (
    (
    NSPoint: {439, 280},
    NSPoint: {439, 280},
    NSPoint: {439, 287},
    NSPoint: {438.62, 290.104},
    NSPoint: {439, 293}
)

)

+1  A: 

You don't need to use NSKeyedArchiver. Instead, just say [[NSUserDefaults standardUserDefaults] setObject:valueArray forKey:@"valueArray"]. The archiving will be done automatically. See if that works.

EDIT: I think your specific problem is using archivedDataWithRootObject:. You don't need to use that, since NSArray conforms to NSCoder--the child objects will also be archived automatically.

eman
I also have this problem. NSPoint is a struct, NSKeyedArchiver cant encode structs.
Luke Mcneice