swiftalamofire

Alamofire convert bool on int


I have func for request and have dictionary for params. Dictionary contained [String, Any]. And i need send Bool in parameters but alamofire convert my Bool on Int and server can't get it. How i can send Bool?

my func:

func postDataFor(methodPath: String, params:[String:Any], completion: @escaping (Any)->()) {
    guard let url = URL(string:baseURL+methodPath) else {print("fail url"); return}

        let token_type = KeychainWrapper.standard.string(forKey: "token_type")
        let access_token = KeychainWrapper.standard.string(forKey: "access_token")

        let headers:HTTPHeaders? = ["Authorization": "\(token_type ?? "") \(access_token ?? "")"]


        Alamofire.request(url, method: .post, parameters: params, encoding: URLEncoding.queryString, headers: headers).response { response in

            if let data = response.data {
                completion(data)
            } else {
           print("error")
        }
    }
}

This i try send:

    ▿ 2 elements
  ▿ 0 : 2 elements
    - key : "promoId"
    - value : 6
  ▿ 1 : 2 elements
    - key : "isFavorite"
    - value : true

But this send alamofire:

?isFavorite=1&promoId=6 

Solution

  • I guess all these values are stored in params. If so, change isFavorite to a string:

    let params = [
        "promoId": 6,
        "isFavorite": String(isFavorite)
    ]