I’ve three totally different knowledge fetching strategies like the next pattern. Three totally different strategies ought to return totally different decodable varieties. The one distinction between these strategies is the Sort that they’d be parsed into. Clearly three totally different strategies is simply code duplication.

It really works that approach however I wish to simplify and refactor that strategies. I’ve three totally different response varieties. I suppose I want to make use of swap case with some enum or use enums as parameters. However I do not understand how to try this.

Thanks.

func fetchProducts(with parameters: CategoryParams, completion: @escaping (ProductsResponse) -> Void) {
        AF.request(productURL, technique: .get, parameters: parameters, headers: headers).responseDecodable(of: ProductsResponse.self) { res in
        swap res.end result {
        case .success:
            DispatchQueue.major.async {
                completion(res.worth!)
            }
        case .failure(let error):
            print(error)
        }
    }
}

By admin

Leave a Reply

Your email address will not be published.