在类型中找不到枚举案例开关

Ste*_*ann 9 enums ios reactive-cocoa swift swift2

有人可以帮我这个.

我有以下内容 public enum

public enum OfferViewRow {
    case Candidates
    case Expiration
    case Description
    case Timing
    case Money
    case Payment

}
Run Code Online (Sandbox Code Playgroud)

以下mutableProperty:

private let rows = MutableProperty<[OfferViewRow]>([OfferViewRow]())
Run Code Online (Sandbox Code Playgroud)

在我的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]
        }
}
Run Code Online (Sandbox Code Playgroud)

但现在问题是,当我试图在我的行中获取枚举的值时,它会抛出错误.请看下面的代码.

 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
        }
    }
Run Code Online (Sandbox Code Playgroud)

它抛出一个错误:Enum case 'some' not found in type 'OfferViewRow就行了let row = rows.value[indexPath.row]

它会抛出每个switch语句: Enum case 'Candidates' not found in type '<<Error type>>

有人可以帮我弄这个吗?

Gwe*_*oué 14

保护声明需要一个可选的,如错误消息中的"Enum case"some暗示.

但事实rows.value[indexPath.row]并非如此Optional<OfferViewRow>,它是一种原始的OfferViewRow.所以它不会进入警卫声明.

向上移动let row = rows.value[indexPath.row]一行:Swift负责边界检查,如果indexPath.row超出界限则会崩溃.