user023 user023 - 1 year ago 86
Swift Question

iOS: Using HanekeSwift with SwiftyJSON

I use Alamofire with SwiftyJSON in my current swift project.
I would like to add HanekeSwift for caching.

Adding HanekeSwift to the project make it "collide" with SwiftyJSON struct JSON.

Is there any easy way to use both of these frameworks?
I know there is a option to rename one of the JSON structs but seems like a stupid workaround. Or do some namespace thing.

Error message:

'JSON' is ambiguous for type lookup in this context

Any solutions to this?

Answer Source

So, the solution that I've found works for me is just to declare the full type of JSON object you are trying to use. E.g. - declare SwiftyJSON.JSON rather than just JSON when expecting or using a SwiftyJSON struct, or Haneke.JSON when you want to use Haneke's JSON enum.

For example, for SwiftyJSON:

var json = SwiftyJSON.JSON(inputObject!)

or for Haneke:

var json = Haneke.JSON(inputObject!)