问题
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