9

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?

Stefan
  • 5,203
  • 8
  • 27
  • 51
hklel
  • 1,624
  • 23
  • 45

6 Answers6

19

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.

teriiehina
  • 4,741
  • 3
  • 41
  • 63
10

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")
tt.Kilew
  • 5,954
  • 2
  • 33
  • 51
5

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.

Community
  • 1
  • 1
rob mayoff
  • 375,296
  • 67
  • 796
  • 848
2

Just delete the old app and run it again works for me

kamrul
  • 59
  • 4
0

I had this issue last night. Sorted it after 3 hours investigating by simply changing the 'Product Name' (under Build Settings) back to the original value.

Charlie S
  • 4,366
  • 6
  • 59
  • 97
-1

I had the same error after only renaming a ClassA that uses the NSCoding protocol to ClassB.

For me the problem was that I had used the ClassA in my UserDefaults. So there was the old name ClassA stored in the UserDefaults .plist.

When the Application was starting it tried to read the .plist and because there was a mismatch in the names the Application crashes.

Solution for me was just to delete the user defaults and run the app again and it worked.

To delete the defaults I used this command in terminal:

defaults delete buldle-identifier