When using Core Data, we obtain the managedObjectContext using our AppDelegate like so:
override func viewDidLoad()
{
super.viewDidLoad()
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
let managedObjectContext = appDelegate.managedObjectContext
}
Now when I remove these two lines of code from viewDidLoad in an attempt to store them as instance variables on ViewController, I get an error.
The issue is that I cannot use "appDelegate", as it is already an instance variable.
I understand that I can solve this by simply doing:
let managedObjectContext = (UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext
However, I was curious if it is possible to declare both as instance variables. I'm assuming that this can be done using getters/setters, but I am not too sure.