How to Use The Delegates with Nskeyedunarchiver

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



Leave a reply



Submit