Solved – type of expression is ambiguous without more context

In this article, you will learn how to solve type of expression is ambiguous without more context. Let’s look at a code example that produces the…

The post Solved – type of expression is ambiguous without more context appeared first on CodeSource.io.


This content originally appeared on CodeSource.io and was authored by Deven

In this article, you will learn how to solve type of expression is ambiguous without more context.

Let’s look at a code example that produces the same error.

Alamofire.upload(
    multipartFormData: { multipartFormData in
        multipartFormData.append(self.imageData, withName: "image", fileName: "file.png", mimeType: "image/png")
    },
to: URL,
    encodingCompletion: { encodingResult in
        switch encodingResult {
        case .success(let upload, _, _):
            upload.responseJSON { response in
                if((response.result.value) != nil) {

                } else {

                }
            }
        case .failure( _):

        }
    }
)

“expression is ambiguous without more context” error means that the compiler is unable to understand what you’re trying to express because you aren’t being specific enough.

In order to solve it, you have put correct arguments. In our case we have to use Alamofire.upload(multipartFormData:with:encodingCompletion:) which takes a URLRequestConvertible for its with: argument.

let url = try! URLRequest(url: URL(string:"www.google.com")!, method: .post, headers: nil)

Alamofire.upload(
    multipartFormData: { multipartFormData in
        multipartFormData.append(Data(), withName: "image", fileName: "file.png", mimeType: "image/png")
    },
    with: url,
    encodingCompletion: { encodingResult in
        switch encodingResult {
        case .success(let upload, _, _):
            upload.responseJSON { response in
                if((response.result.value) != nil) {

                } else {

                }
            }
        case .failure( _):
            break
        }
    }
)

Consider the another code snippet below which produces same error.

....
multipartFormData: { multipartFormData in
        multipartFormData.append(data: imageData!, withName: "unicorn")
    },
....

In the code snippet above we have the wrong arguments for multipartFormDatawhich can be easily fixed like below:

...
multipartFormData: { multipartFormData in
                    multipartFormData.append(imageData!, withName: "photo", fileName: "image.jpg", mimeType: "image/jpg")
                },
...

The post Solved – type of expression is ambiguous without more context appeared first on CodeSource.io.


This content originally appeared on CodeSource.io and was authored by Deven


Print Share Comment Cite Upload Translate Updates
APA

Deven | Sciencx (2021-03-08T08:37:01+00:00) Solved – type of expression is ambiguous without more context. Retrieved from https://www.scien.cx/2021/03/08/solved-type-of-expression-is-ambiguous-without-more-context/

MLA
" » Solved – type of expression is ambiguous without more context." Deven | Sciencx - Monday March 8, 2021, https://www.scien.cx/2021/03/08/solved-type-of-expression-is-ambiguous-without-more-context/
HARVARD
Deven | Sciencx Monday March 8, 2021 » Solved – type of expression is ambiguous without more context., viewed ,<https://www.scien.cx/2021/03/08/solved-type-of-expression-is-ambiguous-without-more-context/>
VANCOUVER
Deven | Sciencx - » Solved – type of expression is ambiguous without more context. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/03/08/solved-type-of-expression-is-ambiguous-without-more-context/
CHICAGO
" » Solved – type of expression is ambiguous without more context." Deven | Sciencx - Accessed . https://www.scien.cx/2021/03/08/solved-type-of-expression-is-ambiguous-without-more-context/
IEEE
" » Solved – type of expression is ambiguous without more context." Deven | Sciencx [Online]. Available: https://www.scien.cx/2021/03/08/solved-type-of-expression-is-ambiguous-without-more-context/. [Accessed: ]
rf:citation
» Solved – type of expression is ambiguous without more context | Deven | Sciencx | https://www.scien.cx/2021/03/08/solved-type-of-expression-is-ambiguous-without-more-context/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.