gpt4 book ai didi

ios - 如何为 Alamofire 请求全局设置基本 url?

转载 作者:可可西里 更新时间:2023-10-31 23:13:40 25 4
gpt4 key购买 nike

到目前为止,我创建的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com