Enum case switch not found in type
Asked Answered
S

1

9

Can someone please help me with this.

I have the following public enum

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

}

And the following mutableProperty:

private let rows = MutableProperty<[OfferViewRow]>([OfferViewRow]())

In my init file I use some reactiveCocoa to set my 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]
        }
}

But now the problem, when I try to get the value of my enum inside my rows it throws errors. Please look at the code below.

 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
        }
    }

It throws an error: Enum case 'some' not found in type 'OfferViewRow on the line let row = rows.value[indexPath.row]

And on every switch statements it throws: Enum case 'Candidates' not found in type '<<Error type>>

Can someone help me with this?

Soapwort answered 19/11, 2015 at 22:2 Comment(3)
can you try public enum OfferViewRow: Int as declaration of enumJanetjaneta
Don't help, also tried the !Soapwort
What is the type of the constant row?Arithmomancy
N
14

The guard statement wants an optional, as hinted by "Enum case 'some'" in the error message.

But rows.value[indexPath.row] is not Optional<OfferViewRow>, it is a raw OfferViewRow. So it won't enter a guard statement.

Move let row = rows.value[indexPath.row] one line up: Swift takes care of bounds checking, and will crash if indexPath.row is out of bounds.

Naked answered 20/11, 2015 at 0:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.