Alamofire.upload SwiftLint违规

问题描述 投票:1回答:1

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

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)

swift alamofire swiftlint
1个回答
3
投票

当有多个闭包参数时,错误告诉您不要使用尾随闭包语法。

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))
    }
})
© www.soinside.com 2019 - 2024. All rights reserved.