有人可以帮助我吗
我有以下公开枚举
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超出范围,将会崩溃.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。