2016-04-03 14 views
8

Amaç, aşağıdaki koşulu Swift 2.2 sözdizimine güncellemektir; bu, #selector or explicitly constructing a Selector kullanılmasını önerir.#selector bağımsız değişkeni, bir özelliğe başvuru yapamıyor

if activityViewController.respondsToSelector("popoverPresentationController") { 

} 

Ancak, yedek başarısız olur ve Argument of #selector cannot refer to a property

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

} 

#selector ile bu çeki uygulamak için doğru yolu nedir belirten bir hata üretir aşağıda kullanarak?

+0

popOverPresentationController bir özellik değildir bir func. Sağ? – Darko

cevap

2

Aşağıdaki sayfada: Eğer iOS hedef eğer kod iOS ile sınırlı değilse

if activityViewController.respondsToSelector(Selector("popoverPresentationController")) { 

} 

Veya sadece

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

} 

Ya

#if os(iOS) 
    if #available(iOS 8.0, *) { 
     activityViewController.popoverPresentationController?.sourceView = sourceView 
    } else { 

    } 
#endif 
İlgili konular