[英]Enum case switch not found in type
有人可以帮我这个。
我有以下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
上的Enum case 'some' not found in type 'OfferViewRow
let row = rows.value[indexPath.row]
它会抛出每个switch语句: Enum case 'Candidates' not found in type '<<Error type>>
有人可以帮我弄这个吗?
保护声明需要一个可选的,如错误消息中的“Enum case”some暗示。
但rows.value[indexPath.row]
不是Optional<OfferViewRow>
,它是原始的OfferViewRow
。 所以它不会进入警卫声明。
将let row = rows.value[indexPath.row]
移动let row = rows.value[indexPath.row]
:Swift负责边界检查,如果indexPath.row超出范围,则会崩溃。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.