Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Swift模拟strings.xml_Swift_String_Api_Endpoint - Fatal编程技术网

如何使用Swift模拟strings.xml

如何使用Swift模拟strings.xml,swift,string,api,endpoint,Swift,String,Api,Endpoint,我想使用结构来设置端点 问题是,当某些端点需要参数时,我的意思是,它在代码上的外观是这样的: on Strings.XML(Android) 我怎样才能在Swift上做第二个 非常感谢您的关注对于此用例,我将使用枚举,如下所示: enum Endpoints { case get_users case get_user_by_id(String) var path: String { switch self { case .get_use

我想使用结构来设置端点

问题是,当某些端点需要参数时,我的意思是,它在代码上的外观是这样的:

on Strings.XML(Android)

我怎样才能在Swift上做第二个


非常感谢您的关注

对于此用例,我将使用枚举,如下所示:

enum Endpoints {
    case get_users
    case get_user_by_id(String)

    var path: String {
        switch self {
        case .get_users:
            return "MyAPI/GetUsers"
        case .get_user_by_id(let id):
            return "MyAPI/GetUser/\(id)"
        }
    }
}
以下

print(Endpoints.get_users.path)
print(Endpoints.get_user_by_id("foo").path)
印刷品

MyAPI/GetUsers
MyAPI/GetUser/foo
您可以使用
字符串(格式:)
并保留占位符。您还可以检查此项(例如,带有关联值的枚举)
print(Endpoints.get_users.path)
print(Endpoints.get_user_by_id("foo").path)
MyAPI/GetUsers
MyAPI/GetUser/foo