Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSKeyedUnarchiver error after renaming Xcode project

I just renamed my Xcode project and when I ran it I got this error:

2015-11-14 05:32:42.337 Buck Tracker[3537:1456100] * Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: '* -[NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class (iBudgeter.Record) for key (NS.objects); the class may be defined in source code or a library that is not linked'

The Buck Tracker is the new name and iBudgeter is the original name. Record is a custom NSObject I created to store some data.

I tried renaming the project back to iBudgeter but it didn't work. Reverting to a previous version in git did help but I got the same error when I renamed it again.

So any suggestions?

like image 786
hklel Avatar asked Nov 13 '15 21:11

hklel


3 Answers

another way is to fix the name of the class used for NSCoding. You simply have to use:

  • NSKeyedArchiver.setClassName("Record", forClass: Record.self before serializing
  • NSKeyedUnarchiver.setClass(Record.self, forClassName: "Record") before deserializing

wherever needed.

Looks like iOS extensions prefix the class name with the extension's name.

like image 166
teriiehina Avatar answered Sep 28 '22 01:09

teriiehina


In Case if you moved your file to another module, you would need to add additional information

NSKeyedArchiver.setClassName("OldModule.ClassName", for: ClassName.self)
NSKeyedUnarchiver.setClass(ClassName.self, forClassName: "OldModule.ClassName")
like image 30
tt.Kilew Avatar answered Sep 28 '22 00:09

tt.Kilew


Don't change your project name. Just change the display name. It's the "Bundle display name" entry in your Info.plist. You'll probably need to add the entry.

adding Bundle display name to Info.plist

See this answer if you want to change the display name of an OS X app.

like image 35
rob mayoff Avatar answered Sep 28 '22 00:09

rob mayoff