Friday, October 7, 2022
HomeiOS Developmentios - Swift get differing types as paramaters? Enums vs Swap...

ios – Swift get differing types as paramaters? Enums vs Swap case?

I’ve three totally different information 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 Kind that they’d be parsed into. Clearly three totally different strategies is simply code duplication.

It really works that method however I wish to simplify and refactor that strategies. I’ve three totally different response varieties. I suppose I would like to make use of change case with some enum or use enums as parameters. However I do not know the way to try this.


func fetchProducts(with parameters: CategoryParams, completion: @escaping (ProductsResponse) -> Void) {
        AF.request(productURL, methodology: .get, parameters: parameters, headers: headers).responseDecodable(of: ProductsResponse.self) { res in
        change res.consequence {
        case .success:
            DispatchQueue.predominant.async {
        case .failure(let error):



Please enter your comment!
Please enter your name here

Most Popular

Recent Comments