How to use Enums as parameters in advanced Swift Protocols features

I have this listing in Swift

enum Direction: Int{ case Left2Right = 0, Right2Left } 

And this protocol

 @objc protocol CellDelegate : NSObjectProtocol{ optional func has(direction:SwipeDirection) -> Bool } 

I get this error Method cannot be marked @objc because the type of the parameter cannot be represented in Objective-C

Can someone tell me why I can get this error and how to fix it? Thanks!

+5
source share
1 answer

The @objc attribute makes the protocol compatible (that is, applicable) with Objective C. But fast enumerations (up to 1.2 beta) are not available in Objective C. Therefore, you cannot use fast enumeration in this protocol.

I think the best solution is to use swift 1.2 - it is still in beta (as of today), but you can apply the @objc attribute to fast transfers.

+7
source

Source: https://habr.com/ru/post/1213633/


All Articles