Swinject - Ambiguous reference to member

☆樱花仙子☆ 提交于 2020-02-02 05:36:06

问题


I am using Swinject in my Swift 3 app. When I tried

let container = Container()
container.register(NetworkModeling.self) { _ in Network() }

I get an error saying

Ambiguous reference to member 'register(_:name:factory:)'

What is wrong here?


回答1:


I faced the same issue and i think compiler could be a bit more verbose in this case.

Anyway, my problem was on my side, not in Swinject

Check the following:

  1. NetworkModeling and Network are visible in scope of your registration (they are public, or internal in the same module. remember, that swift3 introduced fileprivate and many other specifiers, so make sure your identifiers are visible to registeting code

  2. Make sure that Network conforms to NetworkModeling. Being unable to see inheritance, swift compiler raises error about ambigous types for Swinject factory

Hope, this helps



来源:https://stackoverflow.com/questions/39813830/swinject-ambiguous-reference-to-member

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