美文网首页
swift 枚举便利的高阶用法

swift 枚举便利的高阶用法

作者: 秋叶红90 | 来源:发表于2021-09-29 15:43 被阅读0次

枚举遍历的高级用法

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)")
            }
        }
    }

相关文章

网友评论

      本文标题:swift 枚举便利的高阶用法

      本文链接:https://www.haomeiwen.com/subject/nvyjnltx.html