检查枚举情况下
问题描述:
我有一个枚举:检查枚举情况下
enum StoresSortType {
case address, number, lastInspectionDate, distance(CLLocation)
}
我想不带参数只检查的情况下,这样的:
let type = StoresSortType.address
if lastSorting.type == type {
//logic here
}
但我有一个错误:path_to_file.swift:197:69: Binary operator '==' cannot be applied to two 'StoresSortType' operands
在最后一种情况下,我怎么能忽略CLLocation
参数?
答
你可以使用一个switch语句
switch(lastSorting)
{
case .distance:
break
default:
break
}
+0
我怎样才能将它与'type'进行比较? –
你需要做的'StoreSortType'确认为'Equatable'协议。 http://nshipster.com/swift-comparison-protocols/ –