So guys
I was fooling around with Lazy Instantiation in Swift. Everything works using following code:
Both variables were defined as Stored Variable Properties. However when I try to use the lazyily instantiated Stored Variable Property in the initialization of the second Stored Variable Property (hence deleting let appDelegate = (UIApplication.sharedApplication().delegate) as! AppDelegate in the lazy var managedObjectContext closure) I'm getting an error. This error states: instance member 'appDelegate' cannot be used on type ViewController.
Can somebody explain me what I'm doing wrong? Thanks!
I was fooling around with Lazy Instantiation in Swift. Everything works using following code:
Code:
lazy var appDelegate: AppDelegate = (UIApplication.sharedApplication().delegate) as! AppDelegate
lazy var managedObjectContext: NSManagedObjectContext = {
let appDelegate = (UIApplication.sharedApplication().delegate) as! AppDelegate
return appDelegate.managedObjectContext
}()
Both variables were defined as Stored Variable Properties. However when I try to use the lazyily instantiated Stored Variable Property in the initialization of the second Stored Variable Property (hence deleting let appDelegate = (UIApplication.sharedApplication().delegate) as! AppDelegate in the lazy var managedObjectContext closure) I'm getting an error. This error states: instance member 'appDelegate' cannot be used on type ViewController.
Can somebody explain me what I'm doing wrong? Thanks!