Swift3中的一些小变化

解档存储自定义对象时的问题

之前Swift2中解档对象时的方法,从plist中读取两个String属性和一个Double属性.

    required init?(coder aDecoder: NSCoder) {
        access_token = aDecoder.decodeObject(forKey: "access_token") as? String
        expires_in = aDecoder.decodeObject(forKey: "expires_in") as! Double
        uid = aDecoder.decodeObject(forKey: "uid") as? String
    }

在Swift3中,代码运行到expires_in = aDecoder.decodeObject(forKey: "expires_in") as! Double这一行会报错,解档时的代码需要修改为:

      expires_in = aDecoder.decodeDouble(forKey: "expires_in")

推荐阅读更多精彩内容