Thursday, June 7, 2012

So You Decided to Refactor and Broke Unarchiving

So you decided to refactor and change a class name or two. And now you're dead in the water because NSKeyedUnarchiver won't recognize your archived data. Makes sense: you've got an object of a class like ControlViewModel, but you changed it to Model

To solve this, include a line like this that is called anytime before the unarchiving happens: 

[NSKeyedUnarchiver setClass:[Model class] forClassName:@"ControlViewModel"];

You might even want to put this in the +(void)initialize method of the class in question. Just make sure to load it.

Now, unless you're out of your mind, you wouldn't base an entire app's storage paradigm on NSKeyedArchiver, but just in case you have done that, it's pretty flexible.


No comments: