问题描述
我喜欢将 soms 函数和 var 与枚举分开,并认为这是一种方法。 (只是示例代码) 这会导致编译错误“Type 'Self' has no member 'allCases'”
public protocol EnumFunctions: Hashable {
static var numOfCases: Self { get }
}
public extension EnumFunctions {
static var numOfCases: Self {
return self.allCases.count
}
}
我的枚举烹饪计时器
public struct Cook_Time {
// struct naming for the dump command like
// dump(Cook_Time(),name: Cook_Time().structname)
let structname : String = "Cook_Time"
let a = "a"
let allValues = PFTime.allValues
public enum PFTime : String,CaseIterable,EnumFunctions {
case t1m = "1mim"
case t3m = "3min"
case t5m = "5min"
case t10m = "10min"
....
static let allValues = PFTimer.allCases.map { $0.rawValue }
}
}
我该如何解决这个问题?我对此的错误想法是什么?我确实需要 Self 而不是 self,对吗?
此外,如果我在单独的文件中为 PFTime 进行扩展,为什么会出现错误“在范围内找不到类型 'PFTime'”?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)