【问题标题】:Check enum case without parameters [duplicate]检查没有参数的枚举大小写[重复]
【发布时间】:2016-12-05 08:20:07
【问题描述】:

我有一个枚举:

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 参数?

【问题讨论】:

标签: ios swift enums


【解决方案1】:

你可以使用 switch 语句

switch( lastSorting )
{
 case .distance:
 break
 default:
 break
}

【讨论】:

  • 我如何将它与type进行比较?
猜你喜欢
  • 2021-08-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-19
  • 1970-01-01
  • 1970-01-01
  • 2017-03-02
  • 2022-07-08
相关资源
最近更新 更多