0

The code for uploading image with Alamofire triggers a SwiftLint violation. How can it be fixed?

Alamofire.upload(multipartFormData: { (multipartFormData) in

                multipartFormData.append(imageData, withName: "profileImage", fileName: "image.png", mimeType: "image/jpg")
            }, usingThreshold: UInt64.init(), to: requestURL, method: .post, headers: headers) { (result) in
                switch result {
                case .success(let upload, _, _):
                    upload.responseJSON { response in
                        if let error = response.error {
                            completionBlock(.failure(error as NSError))
                            return
                        }
                        completionBlock(.success(response))
                    }
                case .failure(let error):
                    completionBlock(.failure(error as NSError))
                }
            }

Multiple Closures with Trailing Closure Violation: Trailing closure syntax should not be used when passing more than one closure argument. (multiple_closures_with_trailing_closure)

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Luda
  • 7,282
  • 12
  • 79
  • 139

1 Answers1

5

The error is telling you not to use trailing closure syntax when there is more than one closure parameter.

Alamofire.upload(multipartFormData: { (multipartFormData) in
    multipartFormData.append(imageData, withName: "profileImage", fileName: "image.png", mimeType: "image/jpg")
}, usingThreshold: UInt64.init(), to: requestURL, method: .post, headers: headers, encodingCompletion: { (result) in
    switch result {
    case .success(let upload, _, _):
        upload.responseJSON { response in
            if let error = response.error {
                completionBlock(.failure(error as NSError))
                return
            }
            completionBlock(.success(response))
        }
    case .failure(let error):
        completionBlock(.failure(error as NSError))
    }
})
Luda
  • 7,282
  • 12
  • 79
  • 139
rmaddy
  • 314,917
  • 42
  • 532
  • 579