SwiftUI 中CaseIterable的作用?

Code

enum Week: CaseIterable {
            case Sun
            case Mon
            case Tue
            case Wen
            case Thu
            case Fri
            case Sat
        }
        print(Week.allCases)
        
        
        //也可以重写allCases方法
        enum Week2: CaseIterable {
            case Sun
            case Mon
            case Tue
            case Wen
            case Thu
            case Fri
            case Sat
            
            static var allCases: [Week2]{
                return [.Mon, .Tue, .Wen, .Thu, .Fri, Sat, Sun]
            }
        }
        print(Week2.allCases)

 

posted @ 2020-04-03 12:03  liuw_flexi  阅读(766)  评论(0编辑  收藏  举报