Defining context for Core Data with AppDelegate as a singletonCore Data: Quickest way to delete all instances of an entityPassing Data between View ControllersDoes a Core Data parent ManagedObjectContext need to share a concurrency type with the child context?Core Data context and singleton data controllerMultiple NSManagedObjectContexts issueUsing a dispatch_once singleton model in SwiftCore Data background context best practiceCore Data: error: Exception was caught during Core Data change processingSaving text from a UITextView using core data SwiftGetting an error when attempting to run the app in swift - Thread 1: EXC_BAD_ACCESS (code=2, address=0x7ffee4ffdee8)

Pressure inside an infinite ocean?

Introducing Gladys, an intrepid globetrotter

What are the differences between credential stuffing and password spraying?

What was Bran's plan to kill the Night King?

I need a disease

ZSPL language, anyone heard of it?

Word for Food that's Gone 'Bad', but is Still Edible?

Should I dumb down my writing in a foreign country?

What to use instead of cling film to wrap pastry

Can my company stop me from working overtime?

What was the first story to feature the plot "the monsters were human all along"?

Wrong answer from DSolve when solving a differential equation

Emotional immaturity of comic-book version of superhero Shazam

Are there any of the Children of the Forest left, or are they extinct?

Upside-Down Pyramid Addition...REVERSED!

In Stroustrup's example, what does this colon mean in `return 1 : 2`? It's not a label or ternary operator

What is the solution to this metapuzzle from a university puzzling column?

Can I use a fetch land to shuffle my deck while the opponent has Ashiok, Dream Render in play?

Can you Ready a Bard spell to release it after using Battle Magic?

Why does this derived table improve performance?

Point of the Dothraki's attack in GoT S8E3?

Why aren't nationalizations in Russia described as socialist?

Is the set of non invertible matrices simply connected? What are their homotopy and homology groups?

Floor of Riemann zeta function



Defining context for Core Data with AppDelegate as a singleton


Core Data: Quickest way to delete all instances of an entityPassing Data between View ControllersDoes a Core Data parent ManagedObjectContext need to share a concurrency type with the child context?Core Data context and singleton data controllerMultiple NSManagedObjectContexts issueUsing a dispatch_once singleton model in SwiftCore Data background context best practiceCore Data: error: Exception was caught during Core Data change processingSaving text from a UITextView using core data SwiftGetting an error when attempting to run the app in swift - Thread 1: EXC_BAD_ACCESS (code=2, address=0x7ffee4ffdee8)






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















I’m trying to get my head around NSManagedObjectContext for Core Data. Xcode 10.1 provides a fair amount of boilerplate if the Core Data checkbox is selected when creating a new project. But I find it a bit confusing wrt how the current context is set for each view controller. I think I have a better way and am looking for advice to confirm, or to put me back on the right track.



For example, in the boilerplate AppDelegate code, didFinishLaunchingWithOptions provides the context to the MasterViewController like this:



let masterNavigationController = splitViewController.viewControllers[0] as! UINavigationController
let controller = masterNavigationController.topViewController as! MasterViewController
controller.managedObjectContext = self.persistentContainer.viewContex


In the MasterViewContoller, the first use of context picks it up from the fetchedResultsController AND there is code to save the context provided, even though the AppDelegate already has a saveContext() function available to do the same thing:



@objc
func insertNewObject(_ sender: Any)
let context = self.fetchedResultsController.managedObjectContext
let newEvent = Event(context: context)

// If appropriate, configure the new managed object.
newEvent.timestamp = Date()

// Save the context.
do
try context.save()
catch
// Replace this implementation with code to handle the error appropriately.
// fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
let nserror = error as NSError
fatalError("Unresolved error (nserror), (nserror.userInfo)")




In my app with multiple view controllers I have made mistakes trying to re-declare or hand off the context in each one where it’s needed, so had to contend with errors that were caused by inadvertently having more than one context flying around.



So my question is this: Am I making a mistake, or is there some downside to the following approach:



1) Make the AppDelegate a singleton:



class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDelegate {

var window: UIWindow?

static let shared = AppDelegate()



2) In each class where it’s needed, always define the context (I’m assuming I only need one) like this:



let context = AppDelegate.shared.persistentContainer.viewContext


3) Whenever the context needs to be saved, do it like this:



AppDelegate.shared.saveContext()


That seems much simpler, clearer and less prone to errors, and seems to work in my implementation. Are there problems with this that I'm not seeing?










share|improve this question






















  • 2) option makes sense, it’s super easy and work well.

    – Mannopson
    Mar 23 at 1:41

















1















I’m trying to get my head around NSManagedObjectContext for Core Data. Xcode 10.1 provides a fair amount of boilerplate if the Core Data checkbox is selected when creating a new project. But I find it a bit confusing wrt how the current context is set for each view controller. I think I have a better way and am looking for advice to confirm, or to put me back on the right track.



For example, in the boilerplate AppDelegate code, didFinishLaunchingWithOptions provides the context to the MasterViewController like this:



let masterNavigationController = splitViewController.viewControllers[0] as! UINavigationController
let controller = masterNavigationController.topViewController as! MasterViewController
controller.managedObjectContext = self.persistentContainer.viewContex


In the MasterViewContoller, the first use of context picks it up from the fetchedResultsController AND there is code to save the context provided, even though the AppDelegate already has a saveContext() function available to do the same thing:



@objc
func insertNewObject(_ sender: Any)
let context = self.fetchedResultsController.managedObjectContext
let newEvent = Event(context: context)

// If appropriate, configure the new managed object.
newEvent.timestamp = Date()

// Save the context.
do
try context.save()
catch
// Replace this implementation with code to handle the error appropriately.
// fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
let nserror = error as NSError
fatalError("Unresolved error (nserror), (nserror.userInfo)")




In my app with multiple view controllers I have made mistakes trying to re-declare or hand off the context in each one where it’s needed, so had to contend with errors that were caused by inadvertently having more than one context flying around.



So my question is this: Am I making a mistake, or is there some downside to the following approach:



1) Make the AppDelegate a singleton:



class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDelegate {

var window: UIWindow?

static let shared = AppDelegate()



2) In each class where it’s needed, always define the context (I’m assuming I only need one) like this:



let context = AppDelegate.shared.persistentContainer.viewContext


3) Whenever the context needs to be saved, do it like this:



AppDelegate.shared.saveContext()


That seems much simpler, clearer and less prone to errors, and seems to work in my implementation. Are there problems with this that I'm not seeing?










share|improve this question






















  • 2) option makes sense, it’s super easy and work well.

    – Mannopson
    Mar 23 at 1:41













1












1








1








I’m trying to get my head around NSManagedObjectContext for Core Data. Xcode 10.1 provides a fair amount of boilerplate if the Core Data checkbox is selected when creating a new project. But I find it a bit confusing wrt how the current context is set for each view controller. I think I have a better way and am looking for advice to confirm, or to put me back on the right track.



For example, in the boilerplate AppDelegate code, didFinishLaunchingWithOptions provides the context to the MasterViewController like this:



let masterNavigationController = splitViewController.viewControllers[0] as! UINavigationController
let controller = masterNavigationController.topViewController as! MasterViewController
controller.managedObjectContext = self.persistentContainer.viewContex


In the MasterViewContoller, the first use of context picks it up from the fetchedResultsController AND there is code to save the context provided, even though the AppDelegate already has a saveContext() function available to do the same thing:



@objc
func insertNewObject(_ sender: Any)
let context = self.fetchedResultsController.managedObjectContext
let newEvent = Event(context: context)

// If appropriate, configure the new managed object.
newEvent.timestamp = Date()

// Save the context.
do
try context.save()
catch
// Replace this implementation with code to handle the error appropriately.
// fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
let nserror = error as NSError
fatalError("Unresolved error (nserror), (nserror.userInfo)")




In my app with multiple view controllers I have made mistakes trying to re-declare or hand off the context in each one where it’s needed, so had to contend with errors that were caused by inadvertently having more than one context flying around.



So my question is this: Am I making a mistake, or is there some downside to the following approach:



1) Make the AppDelegate a singleton:



class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDelegate {

var window: UIWindow?

static let shared = AppDelegate()



2) In each class where it’s needed, always define the context (I’m assuming I only need one) like this:



let context = AppDelegate.shared.persistentContainer.viewContext


3) Whenever the context needs to be saved, do it like this:



AppDelegate.shared.saveContext()


That seems much simpler, clearer and less prone to errors, and seems to work in my implementation. Are there problems with this that I'm not seeing?










share|improve this question














I’m trying to get my head around NSManagedObjectContext for Core Data. Xcode 10.1 provides a fair amount of boilerplate if the Core Data checkbox is selected when creating a new project. But I find it a bit confusing wrt how the current context is set for each view controller. I think I have a better way and am looking for advice to confirm, or to put me back on the right track.



For example, in the boilerplate AppDelegate code, didFinishLaunchingWithOptions provides the context to the MasterViewController like this:



let masterNavigationController = splitViewController.viewControllers[0] as! UINavigationController
let controller = masterNavigationController.topViewController as! MasterViewController
controller.managedObjectContext = self.persistentContainer.viewContex


In the MasterViewContoller, the first use of context picks it up from the fetchedResultsController AND there is code to save the context provided, even though the AppDelegate already has a saveContext() function available to do the same thing:



@objc
func insertNewObject(_ sender: Any)
let context = self.fetchedResultsController.managedObjectContext
let newEvent = Event(context: context)

// If appropriate, configure the new managed object.
newEvent.timestamp = Date()

// Save the context.
do
try context.save()
catch
// Replace this implementation with code to handle the error appropriately.
// fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
let nserror = error as NSError
fatalError("Unresolved error (nserror), (nserror.userInfo)")




In my app with multiple view controllers I have made mistakes trying to re-declare or hand off the context in each one where it’s needed, so had to contend with errors that were caused by inadvertently having more than one context flying around.



So my question is this: Am I making a mistake, or is there some downside to the following approach:



1) Make the AppDelegate a singleton:



class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDelegate {

var window: UIWindow?

static let shared = AppDelegate()



2) In each class where it’s needed, always define the context (I’m assuming I only need one) like this:



let context = AppDelegate.shared.persistentContainer.viewContext


3) Whenever the context needs to be saved, do it like this:



AppDelegate.shared.saveContext()


That seems much simpler, clearer and less prone to errors, and seems to work in my implementation. Are there problems with this that I'm not seeing?







ios swift core-data nsmanagedobjectcontext






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 22 at 23:07









tkhelmtkhelm

64




64












  • 2) option makes sense, it’s super easy and work well.

    – Mannopson
    Mar 23 at 1:41

















  • 2) option makes sense, it’s super easy and work well.

    – Mannopson
    Mar 23 at 1:41
















2) option makes sense, it’s super easy and work well.

– Mannopson
Mar 23 at 1:41





2) option makes sense, it’s super easy and work well.

– Mannopson
Mar 23 at 1:41












1 Answer
1






active

oldest

votes


















0














To be honest Apple examples / templates always was bad example for beginners, because they show only one thing and "hack" on rest (force unwrapping everything for example). And beginners tend to just copy this approach.



Disclaimer: I talking about middle-big size applications. You always can broke this rules and recommendations in small apps, cause not using them can be easier and lead to simpler application.



Make the AppDelegate a singleton:



In 99% you should not instantiate AppDelegate by self. It handled for you by UIApplication / @UIApplicationMain annotation.



AppDelegate already singleton, since each application has exactly one delegate for whole lifetime. You can access it by UIApplication.shared.delegate as? AppDelegate.



But you shouldn't. AppDelegate play specific role in each app by providing entry point for communication between system and your code and you shouldn't add additional roles to it (as handle database). Accessing it somewhere in codebase in most case signs of code smell and bad architecture.



Separating CoreData stack



DataBase access is one of few examples of good use of Singleton pattern. But instead of using AppDelegate you should make separate service that will be responsible only for handling communication with coredata (such as creating and handling stack, sending queries and etc).



So CoreDataService is way to go.



Accessing core data



Using singletons doesn't mean you can just access it anywhere by typing Singleton.shared. This will highly decrease testability of your components and make them highly coupled to singletons.



Instead you should read about Dependency injection principle and inject your singletons. E.g:



class MyViewController: UIViewController 
let dataBaseManager: CoreDataService
init(with dataBaseManager: CoreDataService)
self.dataBaseManager = dataBaseManager
super.init(nibName: nil, bundle: nil)




Ideally you should go even further to SOLID and provide to controller only what it really needs:



protocol EventsProvider 
func getEvents(with callback: [Event] -> Void)


extension CoreDataService: EventsProvider
func getEvents(with callback: [Event] -> Void)
// your core data query here



class MyViewController: UIViewController
let eventsProvider: EventsProvider
init(with eventsProvider: EventsProvider)
self.eventsProvider = eventsProvider
super.init(nibName: nil, bundle: nil)



let vc = MyViewController(with: CoreDataService.shared)


Multiple contexts



Having multiple NSManagedObjectContext can be handy and improve performance, but only when you know how to work with them.

It's more advance topic, so you can ignore it for now.

You can read about it in Core Data Programming Guide






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55308886%2fdefining-context-for-core-data-with-appdelegate-as-a-singleton%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    To be honest Apple examples / templates always was bad example for beginners, because they show only one thing and "hack" on rest (force unwrapping everything for example). And beginners tend to just copy this approach.



    Disclaimer: I talking about middle-big size applications. You always can broke this rules and recommendations in small apps, cause not using them can be easier and lead to simpler application.



    Make the AppDelegate a singleton:



    In 99% you should not instantiate AppDelegate by self. It handled for you by UIApplication / @UIApplicationMain annotation.



    AppDelegate already singleton, since each application has exactly one delegate for whole lifetime. You can access it by UIApplication.shared.delegate as? AppDelegate.



    But you shouldn't. AppDelegate play specific role in each app by providing entry point for communication between system and your code and you shouldn't add additional roles to it (as handle database). Accessing it somewhere in codebase in most case signs of code smell and bad architecture.



    Separating CoreData stack



    DataBase access is one of few examples of good use of Singleton pattern. But instead of using AppDelegate you should make separate service that will be responsible only for handling communication with coredata (such as creating and handling stack, sending queries and etc).



    So CoreDataService is way to go.



    Accessing core data



    Using singletons doesn't mean you can just access it anywhere by typing Singleton.shared. This will highly decrease testability of your components and make them highly coupled to singletons.



    Instead you should read about Dependency injection principle and inject your singletons. E.g:



    class MyViewController: UIViewController 
    let dataBaseManager: CoreDataService
    init(with dataBaseManager: CoreDataService)
    self.dataBaseManager = dataBaseManager
    super.init(nibName: nil, bundle: nil)




    Ideally you should go even further to SOLID and provide to controller only what it really needs:



    protocol EventsProvider 
    func getEvents(with callback: [Event] -> Void)


    extension CoreDataService: EventsProvider
    func getEvents(with callback: [Event] -> Void)
    // your core data query here



    class MyViewController: UIViewController
    let eventsProvider: EventsProvider
    init(with eventsProvider: EventsProvider)
    self.eventsProvider = eventsProvider
    super.init(nibName: nil, bundle: nil)



    let vc = MyViewController(with: CoreDataService.shared)


    Multiple contexts



    Having multiple NSManagedObjectContext can be handy and improve performance, but only when you know how to work with them.

    It's more advance topic, so you can ignore it for now.

    You can read about it in Core Data Programming Guide






    share|improve this answer



























      0














      To be honest Apple examples / templates always was bad example for beginners, because they show only one thing and "hack" on rest (force unwrapping everything for example). And beginners tend to just copy this approach.



      Disclaimer: I talking about middle-big size applications. You always can broke this rules and recommendations in small apps, cause not using them can be easier and lead to simpler application.



      Make the AppDelegate a singleton:



      In 99% you should not instantiate AppDelegate by self. It handled for you by UIApplication / @UIApplicationMain annotation.



      AppDelegate already singleton, since each application has exactly one delegate for whole lifetime. You can access it by UIApplication.shared.delegate as? AppDelegate.



      But you shouldn't. AppDelegate play specific role in each app by providing entry point for communication between system and your code and you shouldn't add additional roles to it (as handle database). Accessing it somewhere in codebase in most case signs of code smell and bad architecture.



      Separating CoreData stack



      DataBase access is one of few examples of good use of Singleton pattern. But instead of using AppDelegate you should make separate service that will be responsible only for handling communication with coredata (such as creating and handling stack, sending queries and etc).



      So CoreDataService is way to go.



      Accessing core data



      Using singletons doesn't mean you can just access it anywhere by typing Singleton.shared. This will highly decrease testability of your components and make them highly coupled to singletons.



      Instead you should read about Dependency injection principle and inject your singletons. E.g:



      class MyViewController: UIViewController 
      let dataBaseManager: CoreDataService
      init(with dataBaseManager: CoreDataService)
      self.dataBaseManager = dataBaseManager
      super.init(nibName: nil, bundle: nil)




      Ideally you should go even further to SOLID and provide to controller only what it really needs:



      protocol EventsProvider 
      func getEvents(with callback: [Event] -> Void)


      extension CoreDataService: EventsProvider
      func getEvents(with callback: [Event] -> Void)
      // your core data query here



      class MyViewController: UIViewController
      let eventsProvider: EventsProvider
      init(with eventsProvider: EventsProvider)
      self.eventsProvider = eventsProvider
      super.init(nibName: nil, bundle: nil)



      let vc = MyViewController(with: CoreDataService.shared)


      Multiple contexts



      Having multiple NSManagedObjectContext can be handy and improve performance, but only when you know how to work with them.

      It's more advance topic, so you can ignore it for now.

      You can read about it in Core Data Programming Guide






      share|improve this answer

























        0












        0








        0







        To be honest Apple examples / templates always was bad example for beginners, because they show only one thing and "hack" on rest (force unwrapping everything for example). And beginners tend to just copy this approach.



        Disclaimer: I talking about middle-big size applications. You always can broke this rules and recommendations in small apps, cause not using them can be easier and lead to simpler application.



        Make the AppDelegate a singleton:



        In 99% you should not instantiate AppDelegate by self. It handled for you by UIApplication / @UIApplicationMain annotation.



        AppDelegate already singleton, since each application has exactly one delegate for whole lifetime. You can access it by UIApplication.shared.delegate as? AppDelegate.



        But you shouldn't. AppDelegate play specific role in each app by providing entry point for communication between system and your code and you shouldn't add additional roles to it (as handle database). Accessing it somewhere in codebase in most case signs of code smell and bad architecture.



        Separating CoreData stack



        DataBase access is one of few examples of good use of Singleton pattern. But instead of using AppDelegate you should make separate service that will be responsible only for handling communication with coredata (such as creating and handling stack, sending queries and etc).



        So CoreDataService is way to go.



        Accessing core data



        Using singletons doesn't mean you can just access it anywhere by typing Singleton.shared. This will highly decrease testability of your components and make them highly coupled to singletons.



        Instead you should read about Dependency injection principle and inject your singletons. E.g:



        class MyViewController: UIViewController 
        let dataBaseManager: CoreDataService
        init(with dataBaseManager: CoreDataService)
        self.dataBaseManager = dataBaseManager
        super.init(nibName: nil, bundle: nil)




        Ideally you should go even further to SOLID and provide to controller only what it really needs:



        protocol EventsProvider 
        func getEvents(with callback: [Event] -> Void)


        extension CoreDataService: EventsProvider
        func getEvents(with callback: [Event] -> Void)
        // your core data query here



        class MyViewController: UIViewController
        let eventsProvider: EventsProvider
        init(with eventsProvider: EventsProvider)
        self.eventsProvider = eventsProvider
        super.init(nibName: nil, bundle: nil)



        let vc = MyViewController(with: CoreDataService.shared)


        Multiple contexts



        Having multiple NSManagedObjectContext can be handy and improve performance, but only when you know how to work with them.

        It's more advance topic, so you can ignore it for now.

        You can read about it in Core Data Programming Guide






        share|improve this answer













        To be honest Apple examples / templates always was bad example for beginners, because they show only one thing and "hack" on rest (force unwrapping everything for example). And beginners tend to just copy this approach.



        Disclaimer: I talking about middle-big size applications. You always can broke this rules and recommendations in small apps, cause not using them can be easier and lead to simpler application.



        Make the AppDelegate a singleton:



        In 99% you should not instantiate AppDelegate by self. It handled for you by UIApplication / @UIApplicationMain annotation.



        AppDelegate already singleton, since each application has exactly one delegate for whole lifetime. You can access it by UIApplication.shared.delegate as? AppDelegate.



        But you shouldn't. AppDelegate play specific role in each app by providing entry point for communication between system and your code and you shouldn't add additional roles to it (as handle database). Accessing it somewhere in codebase in most case signs of code smell and bad architecture.



        Separating CoreData stack



        DataBase access is one of few examples of good use of Singleton pattern. But instead of using AppDelegate you should make separate service that will be responsible only for handling communication with coredata (such as creating and handling stack, sending queries and etc).



        So CoreDataService is way to go.



        Accessing core data



        Using singletons doesn't mean you can just access it anywhere by typing Singleton.shared. This will highly decrease testability of your components and make them highly coupled to singletons.



        Instead you should read about Dependency injection principle and inject your singletons. E.g:



        class MyViewController: UIViewController 
        let dataBaseManager: CoreDataService
        init(with dataBaseManager: CoreDataService)
        self.dataBaseManager = dataBaseManager
        super.init(nibName: nil, bundle: nil)




        Ideally you should go even further to SOLID and provide to controller only what it really needs:



        protocol EventsProvider 
        func getEvents(with callback: [Event] -> Void)


        extension CoreDataService: EventsProvider
        func getEvents(with callback: [Event] -> Void)
        // your core data query here



        class MyViewController: UIViewController
        let eventsProvider: EventsProvider
        init(with eventsProvider: EventsProvider)
        self.eventsProvider = eventsProvider
        super.init(nibName: nil, bundle: nil)



        let vc = MyViewController(with: CoreDataService.shared)


        Multiple contexts



        Having multiple NSManagedObjectContext can be handy and improve performance, but only when you know how to work with them.

        It's more advance topic, so you can ignore it for now.

        You can read about it in Core Data Programming Guide







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 23 at 1:36









        ManWithBearManWithBear

        1,809720




        1,809720





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55308886%2fdefining-context-for-core-data-with-appdelegate-as-a-singleton%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현