2017-04-17 33 views
2

等號我添加了一個Date擴展,像這樣的公曆的變量:兩人在表達斯威夫特

extension Date { 
    struct Gregorian { 
     static let calendar = Calendar(identifier: .gregorian) 
    } 
} 

我想補充另一個static var公曆結構內的壓光機,其中firstWeekday = 2。這樣的事情:

struct Gregorian { 
    static let calendar = Calendar(identifier: .gregorian) 
    static let calender2 = Calendar(identifier: .gregorian).firstWeekday = 2 
} 

但是,我不能有兩個=聲明。我如何正確實現添加這個新的結構成員?

回答

3

定義和調用一個封閉創建calendar2

struct Gregorian { 
    static let calendar = Calendar(identifier: .gregorian) 
    static let calender2: Calendar = { 
     var c = Calendar(identifier: .gregorian) 
     c.firstWeekday = 2 
     return c 
    }() 
}