简体   繁体   English

Alamofire获取请求网址参数

[英]Alamofire get request url parameters

I need to create a url like "myserverbaseurl.com/category/{id}/subcategory 我需要创建一个网址,例如“ myserverbaseurl.com/category/{id}/subcategory

{id} in this url needs to be parametric and can change. 此网址中的{id}必须是参数化的,可以更改。 The rest of the url is constant. 其余的URL是恒定的。 Does Alamofire have an easy way for this or I need to do this with String? Alamofire是否有简便的方法,还是我需要用String做到这一点?

Start setting your parameter in a constant and use a function to make your call, for example: 开始在常量中设置参数并使用函数进行调用,例如:

func myAPICall(id: String){

    let url = "myserverbaseurl.com/category/" + id + "/subcategory"

    Alamofire.request(url).responseJSON { (response) in 
        ....
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM