Type does not have a member

You cannot initialize an instance class property referencing another instance property of the same class, because it’s not guaranteed in which order they will be initialized – and swift prohibits that, hence the (misleading) compiler error.

You have to move the initialization in a constructor as follows:

let components: NSDateComponents

init() {
    self.components = myCalendar.components(.CalendarUnitYear | .CalendarUnitMonth, fromDate: now)
}

Leave a Comment