I'm writing a network layer, and, I wrote a enum to encapsulate the result of a request:
enum RequestResult<T> {
case success(T)
case error(RequestError)
}
For each request, I can have only success or fail. Then, I can use as this way:
class PostsRequest {
...
static func fetch(completion: @escaping (RequestResult<[Post]>) -> Void) {
But, how I can use my generic RequestResult
in requests that no have results on success, or have many results on success? I can write a generic enum with variable quantities in a case?