0

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];
}

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

3 Comments

I bet it is an instance of NSValue containing a void*.
It is! So, I have to create a new class based on NSValue, or how can I fix this?
@Endanke What about using NSData instead?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.