Questions tagged [managedobjectcontext]

A managed object context represents a single object space, or scratch pad, in a Core Data application on iOS. It's primary responsibility is to manage a collection of managed objects.

An entity on the iOS platform.

A managed object context represents a single object space, or scratch pad, in a Core Data application. A managed object context is an instance of NSManagedObjectContext. Its primary responsibility is to manage a collection of managed objects. These managed objects represent an internally consistent view of one or more persistent stores. The context is a powerful object with a central role in the life-cycle of managed objects, with responsibilities from life-cycle management (including faulting) to validation, inverse relationship handling, and undo/redo.

Link.

48 questions
9
votes
2 answers

Passing context in iOS to use Core Data with Storyboard

I'm having some problems in passing context from the app delegate to the view controller. I've found many tutorials on the internet, and all suggest to use the didFinishLaunchingWithOptions method to create the view controller, set the context…
yassassin
  • 3,185
  • 6
  • 28
  • 31
9
votes
1 answer

Core Data: should I be fetching objects from the parent context or does the child context have the same objects as the parent?

I am slightly confused about parent/child contexts for ManagedObjectContext. When I setup a child context and set the parent context, does the child context contain all the objects of the parent context? I am using the stock Core Data methods that…
The Nomad
  • 7,155
  • 14
  • 65
  • 100
5
votes
2 answers

How to Save Data When Using One ManagedObjectContext and PersistentStoreCoordinator with Two Stores

PROBLEM STATEMENT When attempting to save a record to a read/write store that is one of two SQLite stores assigned to the same PersistentStoreCoordinator, my iPhone app crashes. One obvious issue when saving a record is the…
4
votes
1 answer

Merging multiple child managed object contexts

In my iOS application, I am attempting to sync core data with a web back end. I want to use a separate background managed object context for the sync so I can keep my main context free to accept changes from the ui while the sync is processing. Both…
adamF
  • 961
  • 2
  • 9
  • 23
3
votes
1 answer

Why saving managed object context changes isDeleted value?

I am writing an iOS app using SwiftUI and Core Data. I am very new to Core Data and try to understand something: Why try self.moc.save() changes self.item.isDeleted from true to false? It happens after I delete a Core Data object (isDeleted changes…
mallow
  • 2,368
  • 2
  • 22
  • 63
3
votes
0 answers

NSDocument refuses to update core data changes using NSFetchedResultsController

I have a Document Based Core Data Application. Each NSPersistantDocument has its own Managed Object Context. I can open/create a document and create a Managed Object within fine, but after open/creating a document and then initialising and inserting…
3
votes
1 answer

Save object from child NSManagedObjectContext not available in parent

I'm having trouble with a parent/child managed object context in iOS. I recall a standard use case is to use a temporary child managed object context, so that the user can decide to press save and propagate the changes up to the parent through…
3
votes
3 answers

Saving to iOS managed object context

I have the following code to save an entity to the managed object context. NSError *savingError = nil; if ([self.managedObjectContext save:&savingError]) { NSLog(@"Successfully saved the context."); } else { …
brianhevans
  • 1,183
  • 4
  • 15
  • 28
1
vote
0 answers

Core Data ManagedObjectContext and Private Queue, role of parent context

My macOS app needs to periodically download user read-only data (like stock prices). To do this I have built a dual-context system: @interface MyCoreDataStackManager : NSObject @property (nonatomic, readonly) NSManagedObjectModel*…
Trygve
  • 1,317
  • 10
  • 27
1
vote
2 answers

Cocoa Application - XCode 8 and App Delegate

In XCode 7, I got the managedObjectContext like this: [[[NSApplication sharedApplication] delegate] managedObjectContext] in XCode 8 I get an Error over the managedObjectContext saying: Instance method 'managedObjectContext' not found; How do I…
Aviram Netanel
  • 12,633
  • 9
  • 45
  • 69
1
vote
0 answers

Multithreading coredata with unique constraint for upsert

Hello guys I am developing an app which uses coredata (multithreaded), below is the coredata stack used (this was designed via a tutorial found here: https://www.cocoanetics.com/2012/07/multi-context-coredata/) THE MODEL - (NSManagedObjectModel…
1
vote
0 answers

context saving adds a new entry to table view

I have a tableviewcontroller from where I am calling a another View Controller. This new controller populates the the object on selected table view cell. In the new view controller I am capturing a switch change.When the switch is turned on, I save…
1
vote
1 answer

Core Data Multiple ManagedObjectContext

How the multiple ManagedObjectContext (MOC) works in core data(Swift 2, iOS 9). I have been through lots of links & material online and answers on StackOverflow, but couldn't find exact answer. I want to know, suppose I have created main MOC which…
Tejas
  • 1,050
  • 12
  • 23
1
vote
1 answer

Getting the managedObjectContext in a document-based app for preferences controller

I've got an OSX document-based app, written in Swift and would like to submit some data from my preferences window controller into my managedObjectContext. Because the preferences window doesn't seem to be invoked through the NSPersistentDocument,…
1
vote
1 answer

When working with Core Data, do you keep a non managed object class, and a managed object version of it

I've always wondered when working with core data if there is any value to have model classes that aren't managed objects? If instead to give those objects persistence, your data manager class that handles the core data store knows how to write your…
1
2 3 4