2016-04-03 16 views
8

以下の条件をSwift 2.2の構文に更新します。これは#selector or explicitly constructing a Selectorの使用を推奨しています。#selectorの引数はプロパティを参照できません

if activityViewController.respondsToSelector("popoverPresentationController") { 

} 

しかし、交換が失敗し、Argument of #selector cannot refer to a property

if activityViewController.respondsToSelector(#selector(popoverPresentationController)) { 

} 

#selectorと、このチェックを実装するための正しい方法は何というエラーが発生して、以下のご利用ですか?

+0

popOverPresentationControllerはプロパティではありませんa func。右? – Darko

答えて

2

次を使用することができます。

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 
関連する問題