Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
652 views
in Technique[技术] by (71.8m points)

ios - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...