0
enum Sections: Int {
case parent
case general
}
struct Parent {
let name: String
}
enum General: Int {
case manage
case settings
func title() -> String {
switch self {
case .manage:
return "Manage"
case .settings:
return "Settings"
}
}
}
struct DataProvider {
func data(at index: NSIndexPath) -> ? {
let section = Sections(rawValue: index.section)!
switch section {
case .parent:
print("parent \(Parent(name: "Venkat"))")
return Parent(name: "Venkat")
case .general:
let general = General(rawValue: index.row)!
print(general.title())
return general
}
}
}
这里处理两个不同的值类型,FUNC数据(在指数:NSIndexPath)需要返回基于indexpath值类型。我尝试了协议,但它需要属性要求来处理单元格级别。任何其他实现方法的方法以及“常规”枚举实现在迅速
请添加'CaseCountable' –
@appzYourLife的定义这是我的自定义协议,我编辑了它 – venky
你可以列出'data(at:)'函数可以返回的一些可能的值吗? –