这里有两个使用的例子。
// The name is required. If we cannot decode a name string, the initializer should fail.
guard let name = aDecoder.decodeObject(forKey: PropertyKey.name) as? String else {
os_log("Unable to decode the name for a Meal object.", log: OSLog.default, type: .debug)
return nil
}
// Because photo is an optional property of Meal, just use conditional cast.
let photo = aDecoder.decodeObjectForKey(PropertyKey.photo) as? UIImage
答案 0 :(得分:1)
NSKeyedUnarchiver
最初是一个桥接目标c类,因此您可以使用
decodeObjectForKey(_:)
迅速<3.0
和
decodeObject(forKey:)
迅速> = 3
在内部,它们是同一件事,语法在不断变化,请看一下Thread