문제

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];
}
도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top