Alamofire 5.X "Type of expression is ambiguous without more context"

Title. I've been messing with this for almost a full hour and can't fix this stupid error message
let urlString = "\(baseURL)\(header)"
let jsonData : Data = try! JSONSerialization.data(withJSONObject: parameter, options: .prettyPrinted)

let jsonString = NSString(data: jsonData, encoding: String.Encoding.utf8.rawValue)! as String

print("JSON Params->\(jsonString)")

let headers: HTTPHeaders = [
"Authorization": "XXXXXX",
"Accept": "application/json",
"Content-Type": "application/json"
]


let uploadUrl = try! URLRequest(url: URL(string:urlString)!, method: .post, headers: headers)
AF.upload(
multipartFormData: { (multiPart) in
var keys = [String]()

for (key, img) in images {
if let imageData = img.jpegData(compressionQuality: compressRatio) {
multiPart.append(imageData, withName: key, fileName: key+".png", mimeType: "image/png")
keys.append(key)
}
}

let jsonName = try! JSONSerialization.data(withJSONObject: ["count": keys.count], options: .prettyPrinted)

multiPart.append(jsonName, withName: "names")
multiPart.append(jsonData, withName: "data")
}, with: uploadUrl, encodingCompletion: { encodingResult in
switch encodingResult {
case .success(let upload, _, _):
upload.responseJSON{ response in
if hud{
Loader.init().hide(delegate: vc)
}

switch response.result {
case .success(_):
print("Response->\(response.value)")

if response.value != nil {
let JSON = response.value! as AnyObject
let response = JSON["response"] as! NSDictionary

let success = response.value(forKey: "status")
let success_message = response.value(forKey: "success_message")
let error_message = response.value(forKey: "error_message")

if success as! String {
completion(response.replaceNullsWithBlanks() as NSDictionary, success_message as NSString, true)
} else {
print("Upload failed")
completion([:], error_message as NSString, false)

if alertMsg {
self.presentAlertWithTitle(title: "Alert", message: error_message, vc: vc)
}
}
}
break

case .failure:
print(response.error ?? "Fail")
self.presentAlertWithTitle(title: "Error!", message: (response.error?.localizedDescription)!, vc: vc)
break
}
}
case .failure(let error):
self.presentAlertWithTitle(title: "Error!", message: error.localizedDescription, vc: vc)
}
})
let urlString = "\(baseURL)\(header)"
let jsonData : Data = try! JSONSerialization.data(withJSONObject: parameter, options: .prettyPrinted)

let jsonString = NSString(data: jsonData, encoding: String.Encoding.utf8.rawValue)! as String

print("JSON Params->\(jsonString)")

let headers: HTTPHeaders = [
"Authorization": "XXXXXX",
"Accept": "application/json",
"Content-Type": "application/json"
]


let uploadUrl = try! URLRequest(url: URL(string:urlString)!, method: .post, headers: headers)
AF.upload(
multipartFormData: { (multiPart) in
var keys = [String]()

for (key, img) in images {
if let imageData = img.jpegData(compressionQuality: compressRatio) {
multiPart.append(imageData, withName: key, fileName: key+".png", mimeType: "image/png")
keys.append(key)
}
}

let jsonName = try! JSONSerialization.data(withJSONObject: ["count": keys.count], options: .prettyPrinted)

multiPart.append(jsonName, withName: "names")
multiPart.append(jsonData, withName: "data")
}, with: uploadUrl, encodingCompletion: { encodingResult in
switch encodingResult {
case .success(let upload, _, _):
upload.responseJSON{ response in
if hud{
Loader.init().hide(delegate: vc)
}

switch response.result {
case .success(_):
print("Response->\(response.value)")

if response.value != nil {
let JSON = response.value! as AnyObject
let response = JSON["response"] as! NSDictionary

let success = response.value(forKey: "status")
let success_message = response.value(forKey: "success_message")
let error_message = response.value(forKey: "error_message")

if success as! String {
completion(response.replaceNullsWithBlanks() as NSDictionary, success_message as NSString, true)
} else {
print("Upload failed")
completion([:], error_message as NSString, false)

if alertMsg {
self.presentAlertWithTitle(title: "Alert", message: error_message, vc: vc)
}
}
}
break

case .failure:
print(response.error ?? "Fail")
self.presentAlertWithTitle(title: "Error!", message: (response.error?.localizedDescription)!, vc: vc)
break
}
}
case .failure(let error):
self.presentAlertWithTitle(title: "Error!", message: error.localizedDescription, vc: vc)
}
})
Anyone know what's causing it?
5 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
ZachHandley
ZachHandleyOP2y ago
The first line, .upload
xPsycHoWasPx
xPsycHoWasPx2y ago
is the try! to check what parts is failing ? because i would be careful with “force upwrapping” like that with try! .
ZachHandley
ZachHandleyOP2y ago
I actually fixed it, I changed it to .responseDecodable and made a decodable type
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server