我是Swift初學者,並且確實遇到了這個問題。Swift正確聲明與協議相對應的對象並且擁有超類
我有一個原型單元CurrencySwitchTableViewCell
,它是UITableViewCell
的子類。
class CurrencySwitchTableViewCell: UITableViewCell {
@IBOutlet weak internal var currencySwitchDelegate: AnyObject!
該電池具有currencySwitchDelegate
屬性,它應該是CurrencySwitchDelegate
協議的
protocol CurrencySwitchDelegate {
func didSelectCurrency(currency:Currency)
}
我怎樣才能在CurrencySwitchTableViewCell
聲明,我currencySwitchDelegate
對應CurrencySwitchDelegate
協議AnyObject
?
什麼是這樣的Objective-C代碼的Swift模擬?
NSObject<CurrencySwitchDelegate>
或id<CurrencySwitchDelegate>
附:
我知道我可以宣佈我的財產是
@IBOutlet weak internal var currencySwitchDelegate: CurrencySwitchDelegate!
不過了XCode給我的錯誤與@IBOutlet
修飾符(IBOutlets應該AnyObject
類)
我也是Swift的初學者,但是你不需要聲明'CurrencySwitchDelegate'是'AnyObject'的協議嗎? –
你爲什麼使用@IBOutlet?你是通過接口生成器連接的東西嗎?通常它應該是'var currencySwitchDelegate:CurrencySwitchDelegate?' –
我使用iboutlet來設置從我的單元到實現此協議的viewcontroller的連接 –