Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

-[NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class

I have an error I don't understand after I updated my app. I have an app already in the app store. I have some app specific data archived and stored in a file inside application support directory. I was reading and storing the data every time when the app is launched and sent to background. Everything was fine so far. Now I released an update to the app. After the update when I launch the app and try to unarchive the data it crashes with below exception.

-[NSKeyedUnarchiver decodeObjectForKey:]: 
cannot decode object of class (ProjectName.ProjectFile) for key (root);
the class may be defined in source code or a library that is not linked.

If I delete the app and install the app again everything works fine.

Both my original app and update are written in Swift. I haven't changed the file name also from version 1 to 2. Does any one know what is happening ?

like image 356
MacP123 Avatar asked Sep 15 '25 02:09

MacP123


1 Answers

I found the reason for the above.

Basically I changed the project target name from version 1 to version 2. So it was trying to decode ProjectName2.ProjectFile instead of ProjectName.ProjectFile.

The possible way to avoid is @objc(PFUserUtils) for the class when you start the first version. If you change the target name like me, use NSKeyedUnarchiver.setClass(className forClassName:name) method to set the class name to old one.

like image 151
MacP123 Avatar answered Sep 17 '25 16:09

MacP123