Pregunta

When I try to encode my custom object whit an NSMutableArray, I always get this exception:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'cannot encode (void *) value: <2063e916>'

What could cause this? The mutablearray is initialized, and on that point where it breaks it has data. I'm pretty sure I've done something wrong in the 'encodeWithCoder' method, because if I keep it empty, it runs well.

This is how I tried to convert my mutablearray to an array, but that didn't helped:

- (void) encodeWithCoder:(NSCoder *)encoder {
    [encoder encodeObject:[[NSArray alloc] initWithArray:_myMutableArray] forKey:kMutableArrayKey];
}
¿Fue útil?

Solución

First of all, there is no need to convert a NSMutableArray into a NSArray.

[encoder encodeObject:_myMutableArray forKey:kMutableArrayKey];

The real problem is not in the code you are showing, very probably one of the values in the array doesn't support NSCoding. Note that everything you want to encode has to implement NSCoding protocol.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top