私はswift3にアプリケーションを変換していますが、次の問題が発生しています。タイプ[NSObject:AnyObject]のディクショナリには "value(forKeyPath:...)"というメンバーはありません
@objc required init(response: HTTPURLResponse, representation: [NSObject : AnyObject])
{
if (representation.value(forKeyPath: "title") is String) {
self.title = **representation.value**(forKeyPath: "title") as! String
}
私は次のエラーを取得:
:私はちょうど表現の型としてANYOBJECT使用していましたが、私はそうするならば、私はそこにエラーAnyObject is not a subtype of NSObject
を取得するコードの古いバージョンで
Value of type [NSObject:AnyObject] has no member value.
を
if (representation.value(forKeyPath: "foo") is String) {
let elementObj = Element(response: response, representation:**representation.value(forKeyPath: "foo")**!)
}
NSObjectと(forKeyPath: "title") 'はうまくいきません。 '[String:AnyObject]'を使うことはできますか? –
なぜ単に 'self.title = representation [" title "]'? – vikingosegundo
'value(forKeyPath:'は何をするべきなのでしょうか? – vadian