How can I decode an object when original class is not available?

后端 未结 5 794
面向向阳花
面向向阳花 2021-02-05 00:52

I have an iOS 7 application that saves a custom object to app\'s iCloud Docs folder as a file. For this, I make use of NSCoding protocol.

@interface Person : NSO         


        
5条回答
  •  后悔当初
    2021-02-05 01:05

    Here's a Swift translation for Ferran Maylinch's answer above.

    Had a similar problem in a Swift project after I duplicated the original target in order to have 2 builds of my product. The 2 builds needed to be useable interchangeably.

    So, I had something like myapp_light.app and my app_pro.app. Setting the class fixed this issue.

    NSKeyedUnarchiver.setClass(MyClass1.classForKeyedUnarchiver(), forClassName: "myapp_light.MyClass1")
    NSKeyedUnarchiver.setClass(MyClass1.classForKeyedUnarchiver(), forClassName: "myapp_pro.MyClass1")
    
    
    
    if let object:AnyObject = NSKeyedUnarchiver.unarchiveObjectWithFile("\path\...") {
        var myobject = object as! Dictionary
        //-- other stuff here
    }
    

提交回复
热议问题