NSKeyedArchiver does not work in Swift 3 ( XCode 8)

后端 未结 4 535
悲哀的现实
悲哀的现实 2021-02-02 14:41

I have migrated my project to Swift 3 and NSKeyedArchiver does not work. I actually have a runtime error when trying to decode object like this:

let         


        
4条回答
  •  悲哀的现实
    2021-02-02 15:16

    Swift 3:

    I adopt the double question mark (??) method and it work like a charm in only one line.

    If val is not nil than it is unwrapped and the value returned. If it is nil then aDecoder.decodeInteger(forKey: "val") returned:

    self.val = aDecoder.decodeObject(forKey: "val") as? Int ?? aDecoder.decodeInteger(forKey: "val")
    

提交回复
热议问题