如何在另一个惰性实例化中使用延迟实例化的属性

时间:2014-12-04 13:15:49

标签: ios swift lazy-initialization

Xcode在components的惰性实例化中没有看到我懒惰的实例化属性weekdayLetters。我该如何解决这个问题?

DaysViewController.Type does not have a member named 'components'

lazy var weekdayLetters: [String] = {
    for index in 0...Constants.kNumberOfWeekdays - 1 {
        components.weekday = calendar.firstWeekday + index
        ...
    }
    return ...
    }()

lazy var components: NSDateComponents = {
    let comps = NSDateComponents()
    comps.weekOfYear = 1
    return comps
    }()

lazy var calendar: NSCalendar = {
    return NSCalendar.currentCalendar()
    }()

1 个答案:

答案 0 :(得分:2)

明确self.解决了您的问题:

self.components.weekday = self.calendar.firstWeekday + index
^^^^^                     ^^^^^

据我所知,没有关于此事的文件。