0

I'm getting the Type of expression is ambiguous without more context error in my code and I'm not sure why. I used the same method before and I never got this error before.

I saw similar posts here regarding this error, but none of the solutions fixed it for me. For example I tried changing to to with and it didn't do anything. Any help would be appreciated.

I'm using:

  1. Alamofire version 5.5.0

  2. Xcode version 14.0

  3. Swift version 5.0`

         Alamofire.upload(
         multipartFormData: { multipartFormData in
             if firstButtonFileType == "image"
             {
                 let imgData = firstButtonImage.jpegData(compressionQuality: 0.5)
                 multipartFormData.append(imgData!, withName: "homework", fileName: "homework.png", mimeType: "image/png")
             }
    
             if firstButtonFileType == "document"
             {
                 multipartFormData.append(linkOfFirstFile!, withName: "homework", fileName: "homework." + firstFileExtension, mimeType: "application/pdf")
             }
    
             if secondButtonFileType == "image"
             {
                 let imgData2 = secondButtonImage.jpegData(compressionQuality: 0.5)
                 multipartFormData.append(imgData2!, withName: "homework1", fileName: "homework1.png", mimeType: "image/png")
             }
    
             if secondButtonFileType == "document"
             {
                 multipartFormData.append(linkOfSecondFile!, withName: "homework1", fileName: "homework1." + secondFileExtension, mimeType: "application/pdf")
             }
    
             if thirdButtonFileType == "image"
             {
                 let imgData3 = thirdButtonImage.jpegData(compressionQuality: 0.5)
                 multipartFormData.append(imgData3!, withName: "homework2", fileName: "homework2.png", mimeType: "image/png")
             }
    
             if thirdButtonFileType == "document"
             {
                 multipartFormData.append(linkOfThirdFile!, withName: "homework2", fileName: "homework2." + thirdFileExtension, mimeType: "application/pdf")
             }
    
             multipartFormData.append(defaults.string(forKey: "user_idx")!.data(using: String.Encoding.utf8)!, withName: "student_idx")
             multipartFormData.append(homework_idx.data(using: String.Encoding.utf8)!, withName: "homework_idx")
             multipartFormData.append(defaults.string(forKey: "school_group")!.data(using: String.Encoding.utf8)!, withName: "school_group")
             multipartFormData.append(defaults.string(forKey: "database")!.data(using: String.Encoding.utf8)!, withName: "db")
    
         },
         with: URL_UPLOAD_FILE,
         encodingCompletion: { encodingResult in
             switch encodingResult {
             case .success(let upload, _, _):
                 upload.responseJSON { response in
                     print(response)
                     if response.result.value != nil {
                     } else {
                         // internet connection error
                     }
                 }
             case .failure(let error):
                 print(error)
             }
         }
     )
    
lex
  • 113
  • 8
  • Please add details like alamofire version you are using and Xcode and Swift version – Nirav D Sep 14 '22 at 08:54
  • 1
    Which line is causing the issue? Unrelated, but `aString.data(encoding: .utf8)!, can be simplified into `Data(aString.utf8)`. – Larme Sep 14 '22 at 08:55
  • @NiravD Just added the versions. – lex Sep 14 '22 at 08:59
  • @Larme The error appears at the very beginning of the code, `Alamofire.upload(` – lex Sep 14 '22 at 09:00
  • 1
    I'd start by commenting that whole code. And start writing it again letting the autocomplete helps you. Forget about all the `multipartFormData.append` for now until the method is "recognized". – Larme Sep 14 '22 at 09:01
  • Try once as @Larme mentioned – Nirav D Sep 14 '22 at 09:07

0 Answers0