简体   繁体   English

无法调用非函数类型的值 '((AnyObject) -> AnyObject?)!' - 斯威夫特 3

[英]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,并且遇到了有关objectForKeyobjectFor转换的问题。

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方法以及为什么这种转换不起作用?

Other Example:其他示例:

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.

相关问题 Swift 3 [String:AnyObject]()给出无法调用非函数类型UInt的值->数据 - Swift 3 [String: AnyObject]() gives Cannot call value of non-function type UInt -> Data 在SWIFT 4.1中从Firebase检索数据时,“下标”的使用模棱两可,并且无法调用非函数类型“ AnyObject”的值错误 - Ambiguous use of 'subscript' and Cannot call value of non-function type 'AnyObject' errors retrieving data from Firebase in SWIFT 4.1 快速错误:无法调用非函数类型“ SKSpriteNode”的值 - Swift error: Cannot call value of non-function type “SKSpriteNode” 在Swift 3中无法调用非函数类型'UICollectionView'的值 - Cannot Call Value of Non-Function Type 'UICollectionView' in Swift 3 ResponseSerializer'无法使用Swift 3调用非函数类型'NSHTTPURLResponse?'的值 - ResponseSerializer 'cannot call value of non-function type 'NSHTTPURLResponse?'' with Swift 3 错误:Swift 3上的“无法调用非函数类型的值” - Error: 'Cannot call value of non-function type' on Swift 3 无法调用非功能类型的值 - Cannot call value of non-function type 无法调用非功能类型的值 - Cannot call value of non-function type 不能在swift 2中替换任何对象类型的值 - Cannot subsript a value of type anyobject in swift 2 Swift:类型的值没有成员,无法调用非函数类型的值 - Swift: value of type has no member, cannot call value of non-function type
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM