【发布时间】:2021-03-13 10:47:00
【问题描述】:
在我的 iOS Swift 项目中,我正在尝试使用 AFNetworking 上传图片,但我收到了如下所示的编译时错误。
Cannot convert value of type '(AFMultipartFormData?) -> Void' to expected argument type '[String : String]?'
我使用的版本: pod 'AFNetworking', '~> 4.0' 和 斯威夫特 5.0
我的代码是
func postImageToServer(url: String, parameters: NSDictionary!, video: Data,mimeType:String,fileName:String,name:String,completionHandler:@escaping (URLSessionDataTask, NSDictionary?, Error?)->()) ->() {
manager.post(url as String, parameters: parameters, headers: { (formData: AFMultipartFormData!) in
formData.appendPart(withFileData: video, name: name, fileName: fileName, mimeType: mimeType)
}, progress: { (progress: Progress) in
print("Downloading... progress1: \(String(describing: progress.fractionCompleted))")
}, success: { (operation, responseObject) in
print("Response: \(responseObject!)")
completionHandler(operation,responseObject as? NSDictionary, Error?.self as? Error)
}) { (operation, error) in
print("Error: " + error.localizedDescription)
completionHandler(operation!, nil ,error)
}
}
这是我的错误图片
我也尝试了所有的研究和解决方案来解决它,但我仍然无法修复它。
我认为这是一个语法错误,因为在旧版本中我曾经运行良好,但是当我更新 AFNetworking 时,我收到了这个错误
这里有人已经解决或可以做到。
【问题讨论】:
-
名为'video'的变量的类型是什么?
-
是 var videoData : Data = Data()
-
错误是否表明您应该在字典中包含
Data对象? -
这个错误不是运行时这是一个编译时错误,所以我认为不会有数据类型的问题。
-
我认为这里只需要对代码块进行一些改进
标签: ios swift networking afnetworking swift5