rootstrap / ios-base

Boilerplate for new iOS projects using Swift 5. Provides a handful of functionalities.
https://rootstrap.com/
MIT License
256 stars 63 forks source link

Refactor APIClient to use Decodable objects or any other generic approach #178

Closed glm4 closed 2 years ago

glm4 commented 3 years ago

Currently, the APIClient class tries to parse a dictionary using JSONSerialization, this brings a couple of problems:

  1. single elements or Arrays from a JSON response are not be supported.
  2. The dictionary is then used to convert it into a Data object to then use a JSONDecoder. This is an unnecessary back and forth which adds complexity and more prone to errors.

Ideally, the client would pass a type that would like to get back and the APIClient will handle the rest. An alternativeis to ahve like a middle layer that takes care of the parsing/decoding.