以下初始化目前在调用getEventCalendar
行产生这个错误:懒初始化实例变量与价值依赖于其它的实例变量
不能使用物业 初始化中的实例成员“getEventCalendar”;属性初始值设定项在'self'可用之前运行。
是否有与该依赖于其他对象类型self
的instance variables
的值初始化所述lazy
实例变量的任何适当的方式(不只是self
alone)?我有例如尝试将getEventCalendar
从方法转换为函数,但这也无济于事。
class AbstractEventCalendarClient {
let eventStore: EKEventStore
let entityType: EKEntityType
lazy var eventCalendar = getEventCalendar()
init(eventStore: EKEventStore, entityType: EKEntityType) {
self.eventStore = eventStore
self.entityType = entityType
}
func getEventCalendar() -> EKCalendar? {
// ...
}
}
相关:http://stackoverflow.com/questions/38118429/swift-lazy-instantiating-using-self。 –