有人可以帮助我吗
我有以下公开枚举
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,.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’没有找到类型’OfferViewRow在行let row = rows.value [indexPath.row]
并且在每个switch语句中都会抛出:Enum case’Candidates’not found in type’< Error type>>
有人可以帮我弄这个吗?
解决方法
警告语句想要一个可选的,如错误消息中的“Enum case”一些“”暗示的.
但是rows.value [indexPath.row]不是可选的< OfferViewRow>,它是一个原始的OfferViewRow.所以不会进入警卫声.
Move let row = rows.value [indexPath.row]一行:Swift处理边界检查,如果indexPath.row超出范围,将会崩溃.