![](/img/trans.png)
[英]Cannot convert value of type 'String?.Type' to expected argument type 'String?'
[英]Cannot convert value of type '(AFMultipartFormData?) -> Void' to expected argument type '[String : String]?'
在我的 iOS Swift 項目中,我嘗試使用 AFNetworking 上傳圖像,但出現如下編譯時錯誤。
Cannot convert value of type '(AFMultipartFormData?) -> Void' to expected argument type '[String : String]?'
我使用的版本: pod 'AFNetworking'、'~> 4.0'和Swift 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 時,我收到了這個錯誤
這里有人已經解決或可以做到。
在我的 iOS Swift 項目中,我嘗試使用 AFNetworking 上傳圖像,但出現如下編譯時錯誤。
Cannot convert value of type '(AFMultipartFormData?) -> Void' to expected argument type '[String : String]?'
我使用的版本: pod 'AFNetworking'、'~> 4.0'和Swift 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 時,我收到了這個錯誤
這里有人已經解決或可以做到。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.