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 7522089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:25:20+00:00 2026-05-30T02:25:20+00:00

When we first added Core Data to our app, the tutorial we followed created

  • 0

When we first added Core Data to our app, the tutorial we followed created an NSManagedObjectContext in our app delegate. It recommended that if we used Core Data on other threads, we should add an observer to update our main context when the thread’s context was saved, like so:

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(mergeChanges:)
                                             name:NSManagedObjectContextDidSaveNotification
                                           object:self.managedObjectContext];

This happens once in applicationDidFinishLoadingWithOptions:. However, the documentation for NSManagedObjectContext says:

Several system frameworks use Core Data internally. If you register to receive these notifications from all contexts (by passing nil as the object parameter to an addObserver… method), then you may receive unexpected notifications that are difficult to handle.

This suggests to me that the object parameter ought to be the context that’s being saved (in my case the background context) rather than the main context. Is that the case? Do I need to observe NSManagedObjectContextDidSaveNotification from every NSManagedObjectContext I create?

  • 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-05-30T02:25:21+00:00Added an answer on May 30, 2026 at 2:25 am

    Simon,

    The object in the -addObserver:selector:name:object: method is the source of the notifications. In your case, it should be the background NSManagedObjectContext.

    Should you observe every context you create? As in all things, that depends. For example, sometimes you want to use a context as a scratchpad and will never save anything from it. Why bother to observe it? In general, you want to observe any contexts that mutate the persistent store.

    Andrew

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

Sidebar

Related Questions

Im trying to create a listing app that is core data backed.The first page
I created a fresh project with a core data template. then I added a
I have an iPhone app that has a sqlLite Core Data model that is
I've got a core data app with 2 views. The first view lists Rooms,
I am using Core Data for the first time and was just curious if
I am using Core Data for my app and I have a model Reservation
I have a core data recipe object that contains an ordered list of ingredient
I'm using core data and NSFetchedResultsController in an app, for feeding a UIViewTable with
I have a core data entity called images that has just 2 fields: imageName
I'm working with Core Data for the first time and this has me stumped.

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.