简体   繁体   English

Swift 3 [String:AnyObject]()给出无法调用非函数类型UInt的值->数据

[英]Swift 3 [String: AnyObject]() gives Cannot call value of non-function type UInt -> Data

I am trying to append some parameters to my Alamofire request. 我试图将一些参数附加到我的Alamofire请求中。

var parameters = [String: AnyObject]()

parameters["firstimg"] = fetchedImagesArray[0] as AnyObject?

parameters["secondimg"] = fetchedImagesArray[1] as AnyObject?

Then: 然后:

    for (key, value) in parameters {
        multipartFormData.append(value.data(using: String.Encoding.utf8)!, withName: key)
}

But when I try to append the parameters I get the error: Cannot call value of non-function type UInt -> Data 但是,当我尝试附加参数时,出现错误: 无法调用非函数类型UInt的值->数据

You need to cast value as String to use the data(using: .utf8) method on it: 您需要将value data(using: .utf8)String才能在其上使用data(using: .utf8)方法:

if let stringValue = value as? String {
    multipartFormData.append(stringValue.data(using: String.Encoding.utf8)!)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法调用非函数类型的值 '((AnyObject) -> AnyObject?)!' - 斯威夫特 3 - Cannot call value of non-function type '((AnyObject) -> AnyObject?)!' - Swift 3 无法调用非函数类型的值 '((UInt) -> Data?)!' - 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 'String?' 无法调用非函数类型“String”的值 - Cannot call value of non-function type 'String' 无法调用非功能类型的值 - Cannot call value of non-function type
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM