netguru / ResponseDetective

Sherlock Holmes of the networking layer. :male_detective:

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hide Objective-C nature of XML and HTML body deserializers

akashivskyy opened this issue · comments

As libxml cannot be imported to Swift directly, ResponseDetective currently uses RDTBodyDeserializer, RDTXMLBodyDeserializer and RDTHTMLBodyDeserializer types, thus making its unwanted Objective-C nature public.

Ideally, I'd like to remove all traces of Objective-C files from the project. This could be achieved in a couple of ways:

  1. Use an Objective-C libxml wrapper as an external framework and import it directly in Swift. This is the worst solution because it adds an unwanted third-party dependency to ResponseDetective.

  2. Create a project-private libxml wrapper as a separate framework and import it directly in Swift. This is better than the 1st solution, but adds a lot of unwanted complexity, especially with header search paths, linking and module maps.

  3. Use a project-private module (not to be mistaken with framework) that exposes needed libxml functionalities internally to ResponseDetective, but no further. This is the best solution.

Assuming the 3rd solution is chosen, the proposed implementation would consist of the following files:

  • A .m file that uses libxml and contains implementation of XML and HTML pretty-printing,
  • A non-public .h file that contains interface of above implementation,
  • A .modulemap file that defines a module including the above header.

As a result, ResponseDetective could import XMLPrettyPrinting (exemplary name of module) directly and use refined-for-Swift APIs without them leaking to the outside world.

Well, it looks like Xcode 9.3 fixed this for us – libxml2 is now a module, which means we can do straight import libxml2 in Swift. 🎉