Hi!
Im asking me, if it would be a good idea to make a statement like this in my AppDelegate to access that particular instance of NSManagedObjectContext (AppDelegate.myContext….):
@class AppDelegate: UIResponder, UIApplicationDelegate {
...
static let myContainer = NSPersistentContainer(name:”myContainer”)
static let myContext = myContainer.viewContext
...
}
Then I can acces that instance via
AppDelegate.myContext
Is that rather mindless?
Or should I write
@class AppDelegate: UIResponder, UIApplicationDelegate {
var myContainer = NSPersistentContainer(name: "myContainer")
var myContext = NSManagedObjectContext?
...
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
...
myContext = myContainer.viewContext
...
}
...
}
Is that rather pointless?
Which way should I prefer?
Best regards!