我正在将应用程序转换为 swift3 并遇到以下问题。
@objc required init(response: HTTPURLResponse, representation: [NSObject : AnyObject])
{
if (representation.value(forKeyPath: "title") is String) {
self.title = **representation.value**(forKeyPath: "title") as! String
}
我收到以下错误:
[NSObject:AnyObject] 类型的值没有成员值。
在旧版本的代码中,我只是使用 AnyObject 作为表示的类型,但如果我这样做,我会在AnyObject is not a subtype of NSObject
那里得到错误:
if (representation.value(forKeyPath: "foo") is String) {
let elementObj = Element(response: response, representation:**representation.value(forKeyPath: "foo")**!)
}