NSKeyedArchiver & NSKeyedUnarchiver depending on bundli-ID
The problem is not the bundle id, the problem is that the classes compile differently because they are built into different targets.
You can deal with this by adding a delegate to the keyed unarchiver and implementing:
optional func unarchiver(_ unarchiver: NSKeyedUnarchiver, cannotDecodeObjectOfClassName name: String, originalClasses classNames: [String]) -> AnyClass?
so that you can check the requested class name and return the appropriate matching class in the current target.
How do NSCoder and/or NSKeyedUnarchiver handle multiple decodings of the same object?
They'll share a reference to the same object (unless you go to lengths to change that behavior).
I.e. NSCoding can deal with fully cyclic, omni-directional, complexly connected, object graphs (as long as all graph participants correctly support NSCoding).
Note that encoding delegates is highly atypical. Delegates are usually connected to an unarchived object graph after anarchival and delegates act as a sort of conduit between your archived model layer (or archived view layer, in the case of IB -- the story is more complex, really, for XIB files... but... close enough) and the rest of your app.
`cannotDecodeObjectOfClassName` not invoked in `NSKeyedArchiverDelegate`
Someone helped me on Apple Dev Forum. For details, see:
https://forums.developer.apple.com/thread/76664
Added a custom framework, now Swift can't unarchive data
Moving DemoNote
from the app to a framework did change the module name, which meant that NSKeyedUnarchiver
couldn't find instances of the archived class due to a name mismatch. The fix was to add this line before unarchiving:
NSKeyedUnarchiver.setClass(DemoNote.self, forClassName: "DemoNotesSwift.DemoNote")
In this case, DemoNote.self
gets the current full class name, and DemoNotesSwift.DemoNote
is what the class used to be called when it was part of the app.
This was only necessary because I had previously existing data that I wanted to keep.
In ObjectiveC using delegate how do I send a message without using a UIButton?
In MicroTune.h
file,
instead of #import "Synth.h"
write @class Synth
Related Topics
Swift - How to Deal with Uncaught Exception
Nstoolbarflexiblespaceitem Is Constraint to Nssplitviewitem in Swift
Issue with Returning a Directory Enumerator from Nsfilemanager Using Enumeratoraturl in Swift
Cocoa: Simulating Command+Tab in Cgevent
Table View Cells Changing Colors When Scrolling Swift
What's The Difference Between [String] VS. [(String)]
Uitextview Contentoffset Is Set
Getting Common Data from Two Different Types of Array
Save/Get UIcolor from Userdefaults
Alamofire Post Request with JSON Encoding
How to Use The Delegates with Nskeyedunarchiver
Uibutton Action Is Not Triggered After Constraint Layouts Changed
Realm: Predicate Returning Lazyfiltercollection - How to Convert to Results<T>
Reachability Change Notification Should Be Called Only Once
How to Hide The Status Bar Programmatically in iOS 8
Type 'Int' Does Not Conform to Protocol 'Booleantype'
Instantiating a Nested Class Using Nsclassfromstring in Swift