Reputation: 15042
In my UINavigationController
I check, if it has a property interactivePopGestureRecognizer
before I set it like so:
class UINavigationControllerExtended: UINavigationController, UIGestureRecognizerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
if self.respondsToSelector(Selector("interactivePopGestureRecognizer")) {
self.navigationController?.interactivePopGestureRecognizer?.delegate = self
}
}
}
The property can be set to nil but the property would still exists, so I would assume respondsToSelector
always returns true. Is it necessary to check this at all?
Upvotes: 1
Views: 709
Reputation: 154621
The interactivePopGestureRecognizer
property was added in iOS 7. It make no sense to check if it exists with respondsToSelector
. Just use it.
Because you are calling it with optional chaining, if the interactivePopGestureRecognizer
property is nil
, then:
self.navigationController?.interactivePopGestureRecognizer?.delegate = self
will safely do nothing.
Upvotes: 2