gpt4 book ai didi

swift - Moya + Alamofire 验证每个请求

转载 作者:行者123 更新时间:2023-11-28 06:36:02 26 4
gpt4 key购买 nike

我正在使用 Moya + Alamofire 并且我正在尝试验证每个请求(例如 Alamofire.request(.GET, "https://httpbin.org/get").validate()) 但在 Moya 内。

但是我找不到办法做到这一点。

最佳答案

在您按照 this example 中的描述在您的 TargetType 实现上实现 validate 属性后,这现在是可能的:

// MARK: - TargetType Protocol Implementation
extension MyService: TargetType {
// ...

// Validate setup is not required; defaults to `false`
// for all requests unless specified otherwise.
var validate: Bool {
switch self {
case .showUser, .showAccounts:
return true
case .createUser:
return false
}
}
}

关于swift - Moya + Alamofire 验证每个请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39088336/

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