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")
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容