The goal is to update the below condition to Swift 2.2 syntax, which advises using #selector or explicitly constructing a Selector
.
if activityViewController.respondsToSelector("popoverPresentationController") {
}
However, using the below as a replacement fails and generates an error saying Argument of #selector cannot refer to a property
if activityViewController.respondsToSelector(#selector(popoverPresentationController)) {
}
What's the right way to implement this check with #selector
?
You can use the following:
if activityViewController.respondsToSelector(Selector("popoverPresentationController")) {
}
Or if you target iOS only
if #available(iOS 8.0, *) {
// You can use the property like this
activityViewController.popoverPresentationController?.sourceView = sourceView
} else {
}
Or if your code is not limited to iOS
#if os(iOS)
if #available(iOS 8.0, *) {
activityViewController.popoverPresentationController?.sourceView = sourceView
} else {
}
#endif
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With