gpt4 book ai didi

swift - Alamofire.upload SwiftLint 违规

转载 作者:搜寻专家 更新时间:2023-11-01 06:25:52 24 4
gpt4 key购买 nike

使用 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 Violation: Trailing closure syntax should not be used when passing more than one closure argument. (multiple_closures_with_trailing_closure)

最佳答案

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

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

关于swift - Alamofire.upload SwiftLint 违规,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54908957/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com