到目前为止,我创建的 url 请求是这样的:
Alamofire.request("https://httpbin.org/room/\(user)/\(password)", method: .patch)
每次我创建一个请求时,我都必须将基本 url 放入每个请求中。我可以以某种方式将基本 url 声明为全局常量吗? (此处 https://httpbin.org/
)
最佳答案
你应该使用一个像这样的结构的常量文件
// Constants.swift
struct Api {
static let BaseUrl = "https://httpbin.org"
}
然后,在你的 Controller 上你可以简单地使用这个值
Alamofire.request(Api.BaseUrl + "/room/\(user)/\(password)", method: .patch)
关于ios - 如何为 Alamofire 请求全局设置基本 url?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41119591/