[英]How to use Enums as parameters in Swift Protocols optional functions
我在Swift中有這個枚舉
enum Direction: Int{
case Left2Right = 0, Right2Left
}
而這個協議
@objc protocol CellDelegate : NSObjectProtocol{
optional func has(direction:SwipeDirection) -> Bool
}
我收到此錯誤Method cannot be marked @objc because the type of the parameter cannot be represented in Objective-C
任何人都可以告訴我為什么會出現這個錯誤以及如何解決它? 謝謝!
@objc屬性使協議與Objective C兼容(即可用)。但是在Objective C中沒有swift enums(在1.2 beta之前)。所以你不能在該協議中使用swift enum。
我認為最好的解決方案是使用swift 1.2 - 它仍處於測試階段(截至今天),但可以將@objc
屬性應用於swift枚舉。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.