swift – #selector的参数不能引用属性

swift – #selector的参数不能引用属性,第1张

概述目标是将以下条件更新为 Swift 2.2语法,该语法建议使用#selector或显式构建Selector. if activityViewController.respondsToSelector("popoverPresentationController") {} 但是,使用以下作为替换失败并生成错误,说#selector的参数不能引用属性 if activityViewControll 目标是将以下条件更新为 Swift 2.2语法,该语法建议使用#selector或显式构建Selector.
if activityVIEwController.respondsToSelector("popoverPresentationController") {}

但是,使用以下作为替换失败并生成错误,说#selector的参数不能引用属性

if activityVIEwController.respondsToSelector(#selector(popoverPresentationController)) {}

使用#selector实现此检查的正确方法是什么?

您可以使用以下内容:
if activityVIEwController.respondsToSelector(Selector("popoverPresentationController")) {}

或者,如果您只针对iOS

if #available(iOS 8.0,*) {    // You can use the property like this    activityVIEwController.popoverPresentationController?.sourceVIEw = sourceVIEw} else {}

或者,如果您的代码不仅限于iOS

#if os(iOS)    if #available(iOS 8.0,*) {        activityVIEwController.popoverPresentationController?.sourceVIEw = sourceVIEw    } else {    }#endif
总结

以上是内存溢出为你收集整理的swift – #selector的参数不能引用属性全部内容,希望文章能够帮你解决swift – #selector的参数不能引用属性所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1034413.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-24
下一篇2022-05-24

发表评论

登录后才能评论

评论列表(0条)

    保存