在types中找不到枚举大小写开关
有人可以帮助我这个。
我有以下的public enum
public enum OfferViewRow { case Candidates case Expiration case Description case Timing case Money case Payment }
和下面的mutableProperty:
private let rows = MutableProperty<[OfferViewRow]>([OfferViewRow]())
在我的init文件中,我使用一些reactiveCocoa来设置我的MutableProperty:
rows <~ application.producer .map { response in if response?.application.status == .Applied { return [.Candidates, .Description, .Timing, .Money, .Payment] } else { return [.Candidates, .Expiration, .Description, .Timing, .Money, .Payment] } }
但是现在的问题是,当我尝试在我的行中获取枚举值时,会引发错误。 请看下面的代码。
func cellViewModelForRowAtIndexPath(indexPath: NSIndexPath) -> ViewModel { guard let row = rows.value[indexPath.row], let response = self.application.value else { fatalError("") } switch row { case .Candidates: // Do something case .Expiration: // Do something case .Description: // Do something case .Timing: // Do something case .Money: // Do something case .Payment: // Do something } }
它会抛出一个错误: Enum case 'some' not found in type 'OfferViewRow
行let row = rows.value[indexPath.row]
并在每个开关语句抛出: Enum case 'Candidates' not found in type '<<Error type>>
有人可以帮我弄这个吗?
guard语句需要一个可选的,如错误消息中的“Enum case”some'“所示。
但rows.value[indexPath.row]
不是Optional<OfferViewRow>
,它是一个原始的OfferViewRow
。 所以它不会进入警戒声明。
移动let row = rows.value[indexPath.row]
一行:Swift负责边界检查,如果indexPath.row超出范围,将会崩溃。