Type inference when using lazy instantiation

折月煮酒 提交于 2019-12-10 09:34:03

问题


Why does type inference on Swift not work here when using lazy instantiation of a property?

class GameView: UIView {
    private lazy var animator = UIDynamicAnimator(referenceView: self)
    ...
}

I get an error in relation to the use of self:

Cannot convert value of type ‘(NSObject -> () -> GameView)’ to expected argument type UIView

(Not sure whether the error is meaningful or not-- perhaps I'm not understanding it properly)

...However when it is explicitly typed, then there is no error:

class GameView: UIView {
    private lazy var animator: UIDynamicAnimator = UIDynamicAnimator(referenceView: self)
    ...
}

来源:https://stackoverflow.com/questions/41546060/type-inference-when-using-lazy-instantiation

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