Type inference when using lazy instantiation

2019-05-04 15:54发布

问题:

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)
    ...
}