【发布时间】:2018-04-24 22:49:37
【问题描述】:
enum SearchBarAction {
case Cancel
case Bookmark
case Location
case Category
case Filter
}
@objc protocol SearchBarNavigatorDelegate: class {
optional func searchBarNavigator(clicked: SearchBarAction)
}
这给了我一个错误
Method cannot be a member of an @objc protocol because the type of the parameter cannot be represented in Objective-C
我需要这个方法是可选的,因此我不能删除 @objc 来解决这个问题。
在将枚举作为参数传递给方法时,有什么方法可以使用可选协议方法?
【问题讨论】:
-
您可以传递枚举 rawValue(例如字符串)并转换回枚举。
-
@Darko 该方法有效,但如果我可以通过枚举,我更愿意,因为我希望该方法不接受任何意外字符串
标签: ios objective-c swift