在类型中找不到枚举大小写开关 [英] Enum case switch not found in type
问题描述
我有以下 public enum
public enum OfferViewRow {
case Candidates
case Expiration
case description
case Timing
case Money
case付款
}
以下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,。付款]
} 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()
}
切换行{
case .Candidates:
//做某事
case .Expiration:
//做某事
case。描述:
//做某事
case .Timing:
//做某事
case .Money:
//做某事
案例:付款:
//做某事
}
}
它抛出一个错误:枚举案例'some'没有找到类型'OfferViewRow
在行 let row = rows.value [indexPath.row]
每个交换机语句都会抛出:枚举情况'候选人'未在类型'<<错误类型>>
可以meone帮我这个吗
保护声明需要一个可选项,如错误消息中的Enum case某些所示。 >
但 rows.value [indexPath.row]
不是可选< OfferViewRow>
,它是一个原始的 OfferViewRow
。所以它不会输入保密声明。
移动 let row = rows.value [indexPath.row]
一行:Swift处理边界检查,如果indexPath.row超出范围,将会崩溃。
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?
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.
这篇关于在类型中找不到枚举大小写开关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!