枚举遍历的高级用法
class People {
enum CodingKeys:String{
static func crateTB() {
}
case name
case title
static func toTest() {
var allKeys:[CodingKeys] = []
var i = 0
while true {
if let key = (withUnsafePointer(to: &i) { t -> CodingKeys? in
let res = t.withMemoryRebound(to: CodingKeys?.self, capacity: 1) { m in
return m.pointee
}
print(" t == \(t)")
return res
}) {
allKeys.append(key)
}else{
break
}
i += 1
}
print("allKeys === \(allKeys)")
}
}
}
枚举遍历方法2
enum Test:CaseIterable {
case make
case llte
func nameTest() {
for item in Test.allCases {
print("====item \(item)")
}
}
}
网友评论