静态和懒惰变量:类似的行为?

时间:2017-03-21 16:26:38

标签: swift syntax

将'dateFormatter'评估一次,就像懒惰一样?

class Birthday {

  private static var dateFormatter: DateFormatter = {
    let formatter = DateFormatter()
    formatter.locale = Locale(identifier: "en_US_POSIX")
    formatter.dateFormat = "d MMMM yyyy"
    return formatter
  }()

  private let date: Date

  init(date: Date) {
    self.date = date
  }

}

ASDF

0 个答案:

没有答案