fatal error: use of unimplemented initializer 'init()' for class

I’m getting an exception when implementing nscoding and saving the object to backendless.

I can save / open the object locally and if i remove the nscoding i can save it to backendless.

Is there a way around this?

Thanks

Could you please attach the code which demonstrates what you’re doing?

Regards,
Mark

So the object does get saved to backendless before it throws an exception.

class testObject: NSObject, NSCoding { 
 
 var name : String 
 
 
 
 init(name: String=String()) { 
 
 self.name = name 
 
 } 
 
 
 
 required convenience init(coder decoder: NSCoder) { 
 
 self.init() 
 
 self.name = decoder.decodeObjectForKey("name") as! String 
 
 } 
 
 
 
 func encodeWithCoder(coder: NSCoder) { 
 
 coder.encodeObject(self.name, forKey: "name") 
 
 } 
 
} 
 



 var test = testObject() 
 
 test.name = "Jimmy" 
 
 var filePath = documentsDirectory().stringByAppendingPathComponent("fileName") 
 
 NSKeyedArchiver.archiveRootObject(test, toFile: filePath) 
 
 let names = NSKeyedUnarchiver.unarchiveObjectWithFile(filePath) as? testObject 
 
 print("%@",names?.name) 
 
 let dataStore = backendless.data.of(testObject.ofClass()) 
 
 
 
 
 // save object asynchronously 
 
 dataStore.save( 
 
 test, 
 
 response: { (result: AnyObject!) -> Void in 
 
 let obj = result as! testObject
 
 print("name has been saved: \(obj.objectId)") 
 
 }, 
 
 error: { (fault: Fault!) -> Void in 
 
 print("Server reported an error: \(fault)") 
 
 }) 
 
 
 



Thanks, Robert. I assigned it to a developer for investigation

Have they been able to duplicate it, work around, fix?

Thanks
Robert

Hi Robert,

I am going to investigate this issue tomorrow.

Regards,
Slava

Hi Robert,

I’ve made some fixes in your sample, and it works fine now:

class testObject: NSObject, NSCoding {
 
 var objectId : String?
 var name : String
 
 override init() {
 self.name = "?"
 }
 
 init(name: String) {
 self.name = name
 }
 
 required convenience init(coder decoder: NSCoder) {
 self.init()
 self.name = decoder.decodeObjectForKey("name") as! String
 }
 
 func encodeWithCoder(coder: NSCoder) {
 coder.encodeObject(self.name, forKey: "name")
 }
}
 func testObjectWithNSCoding() {
 
 let test = testObject(name: "Jimmy")
 let dataStore = backendless.data.of(testObject.ofClass())
 
 // save object asynchronously
 dataStore.save(
 test,
 response: { (result: AnyObject!) -> Void in
 let obj = result as! testObject
 print("name has been saved: \(obj.objectId)")
 },
 
 error: { (fault: Fault!) -> Void in
 print("Server reported an error: \(fault)")
 })
 }

Try this fixed code and let us know how it goes.

Regards,
Slava

Thank You!