I have a custom subclass of UIView. It has a pan gesture recognizer that I've set up as a required constant:
let dragger: UIPanGestureRecognizer
It's a constant because it's created once at initialization of the view and persists for the lifetime of the view.
In the view's designated initializer, init(coder)
, I want to create my pan gesture recognizer and wire it up. However, Under Xcode 6.3, it seems I can't do that if the gesture recognizer is a constant. (This only seems to be a problem under the Xcode 6.3 beta The code allows me to set the pan gesture initializer after the call to super.init(coder)
)
Since the variable is a required constant, it needs to be set up before I call the superclass init(coder)
. However, the only initializer for a pan gesture recognizer takes self as a parameter. Self isn't available until after I've called super.init(coder)
.
So, I can't create my gesture recognizer with a call to UIPanGestureRecognizer(target:action:)
before the call to super.init(coder)
because I need to pass self to that pan gesture initializer,
...and I can't call UIPanGestureRecognizer(target:action:)
AFTER the call to super.init(coder)
, because I have to set values for all required constants/variables before calling the superclass initializer.
The only solution I can come up with is to make my gesture recognizer an optional var, which I'd rather not do. It will always have a value after the initializer completes, and having to unwrap an optional every time I use it is annoying.
Am I missing something here?