如何根据需要使用可选参数修复解析?

时间:2019-04-29 18:14:26

标签: swift xcode moya

我正在尝试使用可选参数进行请求,但是当我不传递参数时,如果在调用中传递参数,则解析通常会发生,我的解析等于nil。

case userAccount(first: Int?, max: Int?, option: String?)

case .userAccount(let first, let max, let option):

            return .requestParameters(parameters: [
                "first": first ?? 0,
                "placeToId": max ?? 0,
                "option": option ?? "balance"], encoding: encoding)
func account(first: Int?, max: Int?, option: String?, completion: @escaping (ResponseResult<UserAccountModel>) -> ()) {
        request(target: .userAccount(first: first, max: max, option: option), completion: completion)
    }

如果我将所有func参数传递为nil,则我的解析有效,但如果我传递了param,则所有解析均无效,并且模型中的每个对象均为nil

0 个答案:

没有答案