0

I'm implementing my own keyed NSCoder subclass and decoding is failing for an NSString.

If I do something like the following:

MyUnarchiver *aDecoder = [[MyUnarchiver alloc] initWithData:someArchivedData];
NSString *aString = [[NSString alloc] initWithCoder:aDecoder];

Then the following "uncaught exception" is thrown:

*** Terminating app due to uncaught exception 'NSGenericException', reason: 'NSString cannot decode class version 12345'

Where 12345 is coming from this method in MyUnarchiver, I presume:

-(NSInteger)versionForClassName:(NSString *)className
{
    return 12345;
}

Similarly, if we throw a nil NSCoder at NSString's initWithCoder: then we get the same error as above, but the version number is 0.

I suspect it might have to do with the fact that I have no idea what I should be implementing in the versionForClassName: method. Even from the Archives and Serializations: Subclassing NSCoder reference I'm unable to glean much on this.

Ncat
  • 417
  • 3
  • 10

1 Answers1

0

Aaaand.... in the course of writing out the question, I realized that I hadn't implemented the allowsKeyedCoding method, which seems to have at least mitigated the issue.

However, I'm still unsure what should be implemented in versionForClassName: if anything. I just deleted it from my implementations and everything seems to be working just as well.

Hope this helps someone.

Ncat
  • 417
  • 3
  • 10