Swift Vapor and modules; how to distinguish two overlapping 'type symbols'

168 views Asked by At

I am looking to reuase some (iOS) client side code into a sample Vapor serverside project.

The code in question relies on SwiftyJSON functionality, defined as a struct JSON; now this name slot is not 'free', but already used inside a package that Vapor relies upon (the package name is JSON, as well).

While I can point to the JSON thing I want in my former client side code (as App.JSON), the controller that is boilerplated into the code also uses JSON. And apparently putting as I did the SwiftyJSON library files into the App namespace actually overrides the moduleless references to Vapor's JSON.

I tried to refer then to JSON.JSON, but it does not get recognized. JSON is a defined and compiled framework in the project. Should it not define implicitely a module name, as well?

How can I reach Vapor's JSON, then?

Thanks..

1

There are 1 answers

0
tobygriffin On BEST ANSWER

As a matter of fact, the Vapor module also exports JSON. So, the following works:

import Vapor

// Introduce a symbol collision
struct JSON {}

// Import from the Vapor module
print(try Vapor.JSON(node: "test"))