问题
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?
回答1:
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!)
回答2:
Found a nice solution for me at the HanekeSwift/issues.
Inside my class with conflicting imports declared as follows
typealias JSON = SwiftyJSON.JSON
Hope it might be usefull for someone
来源:https://stackoverflow.com/questions/28855910/ios-using-hanekeswift-with-swiftyjson