Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8357415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:28:08+00:00 2026-06-09T10:28:08+00:00

So I’m building a document-based application in Cocoa and trying to understand NSManagedObjectContext. I’ve

  • 0

So I’m building a document-based application in Cocoa and trying to understand NSManagedObjectContext. I’ve read Apple’s “Core Data Basics” but can’t wrap my head around it. In my application I created a custom CoreDataUtility class so that all of my classes can get the context via the following lines of code:

MyCoreDataUtility *coreData = [MyCoreDataUtility sharedCoreDataUtility];
NSManagedObjectContext *context = [coreData context];

I got this idea from the site “Cocoa is my girlfriend”. Where I get confused is when I run my application and I create a new window (my file owner class is a subclass of NSPersistentDocument) if I make changes to the context on the new window, the view reflects the changes on the old window and as well as the new one. Based on this I’m assuming that both windows are referring to the same context or at least the same data in some way.

So my questions are:

  1. I have the assumption that each time I create a new window a new
    context is created, is this correct?
  2. If a new context is created and they are different (I actually
    printed out the memory address of the two contexts and they
    addresses are different) does this have something to do with the
    persistent store coordinator or persistent object store (both of
    these concepts are also nebulous in my mind)?
  3. If all documents refer to the same context is it my responsibility to
    create a new context every time a document is created?

Thanks all!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T10:28:10+00:00Added an answer on June 9, 2026 at 10:28 am

    I have the assumption that each time I create a new window a new
    context is created, is this correct?

    No and yes. Creating a new window does not create a new context, but I suppose that what you see as “a new window” is actually your action of “creating a new document”. In a document based app with CoreDate you are likely to have a persistent store which creates a new context for every document by itself.

    That is also the answer to your second question. The store coordinator is just the central point that manages all documents of your application. It takes care of some menu related actions, such as opening, saving and all side effects.

    If all documents refer to the same context is it my responsibility to
    create a new context every time a document is created?

    That is not possible. One context can be related with only one file (or “store”), hence every document must have “at its minimum” one context. If you are using the template for a CoreData and Multi-document based app, you do not have to worry about creating a new context. As I said before, the store coordinator will take care of that. However as you learn more about CoreData, and specially if you do multithreading, you will have to create more than one context because because a context cannot cross threads.

    Could you provide the link from Cocoa is my girlfriend where you took that code? It seems you want a singleton to store your context and usually that is a bad idea in a document based app because it is extremely easy to mess up things giving one function the context of a different document. Your application should have a good flow where the context is passed. However I always use a singleton if my application is not document based.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I want to construct a data frame in an Rcpp function, but when I
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I am trying to render a haml file in a javascript response like so:
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.