So, I have a Today View widget built from my main application, and I'm trying to access some saved data (via CoreData). But when I create a lazy variable to process one of my entities, it does not compile. I understand the error that it throws, but I'm not sure how to handle / fix it.
lazy var managedObjectContext : NSManagedObjectContext? = { let appDelegate = UIApplication.sharedApplication().delegate as AppDelegate if let managedObjectContext = appDelegate.managedObjectContext { return managedObjectContext } else { return nil } }()
The error is displayed on line 2 on ... "as AppDelegate", which is "Undeclared use of AppDelegate". I think it makes sense, because AppDelegate is located in the folder of the base application, and not in the widget folder. But I am losing the opportunity to replace or fix this so that the code compiles and functions. Any ideas?
source share