iOS: Using HanekeSwift with SwiftyJSON

南楼画角 提交于 2019-12-07 15:53:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!