Pergunta

I'm trying to unarchive an array of objects of a particular type, but the initWithCoder: function does not get executed within the object's class. Instead, I'm given the error:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SavedObject initWithCoder:]: unrecognized selector sent to instance 0x9e85f34'

Now, the strange thing is, the encodeWithCoder: is called and I'm able to write the data to disk just fine. Then when attempting to read the data back, the data looks exactly like that which was written to disk.

Writing to disk:

// arrayOfObjectsToSave
NSData *arrayData = [NSKeyedArchiver archivedDataWithRootObject:arrayOfObjectsToSave];
// uses NSData writeToURL - Works fine!
[self writeToDisk:arrayData];

With a po command in the console, I can confirm the arrayData looks something along the lines of:

<62706c69 73743030 ... 00000000 00000288>

Reading the data back:

// url passed through
NSData *readBack = [self readDataFromURL:dataURL];
NSArray *persisitedArray = [NSKeyedUnarchiver unarchiveObjectWithData:readBack]

the readBack data is:

<62706c69 73743030 ... 00000000 00000288>

but the app seems to crash on the unarchiveObjectWithData: line with the error above, but doesn't seem to even call initWithCoder: on my class.

And to top it all off ... it works fine on iOS 7

Foi útil?

Solução

I have managed to resolve the issue by renaming the class entity. All the existing code works as expected now.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top