我正在尝试重构代码并创建一个枚举类来保存表格视图单元格的 indexPath。
我想让代码这样工作:
enum TableViewCell: IndexPath {
case shopImageView = [0,0]
case selectShopImageButton = [0,1]
}
但是编译器说 indexPath 不是 rawRepresentable:
'TableViewCell' 声明了原始类型 'IndexPath',但不符合 RawRepresentable 并且无法合成一致性
枚举大小写的原始值必须是文字
如何使 indexPath rawRepresentable?代码目前是这样工作的,我想改进它。
enum TableViewCell {
case shopImageView
case selectShopImageButton
case shopNameLocal
case shopNameEN
case addressLocal
case addressEN
case selectAddressButton
case openingHours
case datePickers
case phone
case email
case uploadShopFormButton
var indexPath: IndexPath {
switch self {
case .shopImageView: return [0,0]
case .selectShopImageButton: return [0,1]
case .shopNameLocal: return [0,2]
case .shopNameEN: return [0,3]
case .addressLocal: return [0,4]
case .addressEN: return [0,5]
case .selectAddressButton: return [0,6]
case .openingHours: return [0,7]
case .datePickers: return [0,8]
case .phone: return [0,9]
case .email: return [0,10]
case .uploadShopFormButton: return [0,11]
}
}
}