How can I decode an object when original class is not available?

This might be another solution, and it’s what I did (since I didn’t use Swift at that time).

In my case, I archived an object of class “City” but then renamed the class to “CityLegacy” because I created a completely new “City” class.

I had to do this to unarchive the old “City” object as a “CityLegacy” object:

// Tell the NSKeyedUnarchiver that the class has been renamed
[NSKeyedUnarchiver setClass:[CityLegacy class] forClassName:@"City"];

// Unarchive the object as usual
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSData *data = [defaults objectForKey:@"city"];
CityLegacy *city = [NSKeyedUnarchiver unarchiveObjectWithData:data];

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)