Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift decodeObject(forKey:)和&;之间有什么区别;decodeObjectForKey(:)_Swift_Nscoding - Fatal编程技术网

Swift decodeObject(forKey:)和&;之间有什么区别;decodeObjectForKey(:)

Swift decodeObject(forKey:)和&;之间有什么区别;decodeObjectForKey(:),swift,nscoding,Swift,Nscoding,这里有两个正在使用的示例 // 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: O

这里有两个正在使用的示例

// 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

nskeyedunachiver
最初是一个桥接的objective c类,因此您可以使用

decodeObjectForKey(:)
In swift=3


在内部,它们是相同的东西,语法发生了变化,看看这个

您是否尝试过两者都使用,或者您只是在询问它们?根据您的Swift/iOS/macOS版本,只有一个可以工作。非常感谢您,我是编程新手,我预计这可能只是语法上的一个变化,但我不确定。