【问题标题】:Append parameters in Alamofire Swift在 Alamofire Swift 中附加参数
【发布时间】:2020-04-06 13:56:10
【问题描述】:

我有跟随数组

let p = [
        "id": id
    ]

如果它们被添加,我想附加它们。

    if (minPriceUsed) {
        //p.add(["minPrice": minPriceText!])
    }
    if (maxPriceUsed) {
        //p.add(["maxPrice": maxPriceText!])
    }

但是,我没有看到此数组类型的任何附加或添加等内容。

【问题讨论】:

    标签: swift alamofire


    【解决方案1】:

    Alamofire 参数是一个字典而不是数组。所以你需要像这样添加新项目

    if (minPriceUsed) {
          p["minPrice"] = minPriceText!
    }
    if (maxPriceUsed) {
          p["maxPrice"]. = maxPriceText!
    }
    

    更多信息:https://github.com/Alamofire/Alamofire/blob/master/Documentation/Usage.md#making-requests

    【讨论】:

      【解决方案2】:

      你需要的是字典而不是数组

      var p = [
          "id": id
      ]   
      

      if minPriceUsed {
          p["minPrice"] = minPriceText!
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-03-03
        • 2023-03-21
        • 1970-01-01
        • 2017-09-21
        • 1970-01-01
        相关资源
        最近更新 更多