[英]Cannot call value of non-function type '((AnyObject) -> AnyObject?)!' - Swift 3
I am trying to convert my current project to Swift 3 and am running into problems regarding the objectForKey
to objectFor
conversion.我正在尝试将我当前的项目转换为 Swift 3,并且遇到了有关
objectForKey
到objectFor
转换的问题。
The type of myData is AnyObject
myData 的类型是
AnyObject
Before :
之前:
let x = myData.objectForKey('myKey')
Now :
现在:
let x = myData.objectFor('myKey') // not working.
In the second case, XCode gives me error Cannot call value of non-function type '((AnyObject) -> AnyObject?)!'
在第二种情况下,XCode 给我错误
Cannot call value of non-function type '((AnyObject) -> AnyObject?)!'
which I have no idea how to fix.我不知道如何解决。
Does anyone know how to updated the objectForKey
method and why this conversion is not working?有谁知道如何更新
objectForKey
方法以及为什么这种转换不起作用?
I created another example in a playground to reproduce this issue.我在操场上创建了另一个示例来重现这个问题。 The lines of code used are pasted below.
使用的代码行粘贴在下面。 The outcome of running this is the same error as stated above.
运行它的结果是与上述相同的错误。
var x: AnyObject = ["Hello" : "Goodbye"] as AnyObject
x.objectFor("Hello")
The syntax has changed from:语法从:
let x = myData.objectForKey("myKey")
to:到:
let x = myData.object(forKey:"myKey")
in Swift 3.在斯威夫特 3 中。
Example:示例:
var x : AnyObject = ["Hello" : "Goodbye"] as AnyObject
x.object(forKey:"Hello")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.