解檔存儲自定義對象時的問題
之前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")