I have API that have path and an int after it.
For example, /get/news/{id}.
For path endpoints i have enum like that:
enum Endpoints : String {
case news = "news"
}
Is there any convinient way to use associated values with it?
Something like :
case newsById(id: String) = "get/news/" + id
                You can use this:
enum APIEndpoints {
    case news(id: Int)
    var path: String {
        switch self {
        case let .news(id):
            return "/get/news/\(id)"
        }
    }
}
And use it like: APIEndpoints.news(id: 5).path
You can always add a function to the enum to get the URI:
enum Endpoints : String {
    case news = "news"
    func getUri(id: string) -> String {
        return "get/\(self.rawValue)/\(id)"
    }
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With