加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-14 05:29:09 所属栏目:百科 来源:网络整理
导读:目标是将以下条件更新为 Swift 2.2语法,该语法建议使用#selector或显式构建Selector. if activityViewController.respondsToSelector("popoverPresentationController") {} 但是,使用以下作为替换失败并生成错误,说#selector的参数不能引用属性 if activityV
目标是将以下条件更新为 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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读