Alamofire.upload SwiftLint违反

时间:2019-02-27 15:29:24

标签: swift alamofire swiftlint

使用Alamofire上传图像的代码会触发SwiftLint违规。怎么解决?

for idx := 0; idx < len(databaseInstance.IpAddresses) ; idx++ {
fmt.Printf("%v ",databaseInstance.IpAddresses[idx].IpAddress)}
  

多个封包违反尾封:尾封   传递多个闭包参数时,不应使用语法。   (multiple_closures_with_trailing_closure)

1 个答案:

答案 0 :(得分:2)

错误是告诉您在有多个闭包参数时不要使用结尾闭包语法。

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))
    }
})