Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass enum as a parameter in a optional method within a protocol

enum SearchBarAction {
  case Cancel
  case Bookmark
  case Location
  case Category
  case Filter
}

@objc protocol SearchBarNavigatorDelegate: class {
  optional func searchBarNavigator(clicked: SearchBarAction)
}

This gave me an error

Method cannot be a member of an @objc protocol because the type of the parameter cannot be represented in Objective-C

I need this method to be optional therefore i cannot remove @objc to solve this.

Is there any way to use optional protocol method while passing an enum as a parameter to the method?

like image 367
WKL Avatar asked May 06 '16 15:05

WKL


1 Answers

It will work if you declare the enumeration as @objc with raw type:

@objc enum SearchBarAction: Int {
    case cancel
    case bookmark
    case location
    case category
    case filter
}
like image 162
Rob Avatar answered Nov 10 '22 00:11

Rob