nsmanagedobjectcontext

Why does Core Data take so long to save an object?

♀尐吖头ヾ 提交于 2019-12-23 03:49:26
问题 I have a simple method in my entity category that adds custom methods to my subclassed NSManagedObject classes (which I don't touch because of automatic subclassing generating). I have this method that deletes an object from the MOC and saves the context. + (void)deleteWishlist:(Wishlist *)wishlist inManagedObjectContext:(NSManagedObjectContext *)context { [context deleteObject:wishlist]; NSError *error; if(![context save:&error]) { NSLog(@"%@", error); } else { NSLog(@"Delete successful"); }

Configure NSFetchedResultsController in background when launching Core Data app

无人久伴 提交于 2019-12-22 17:39:09
问题 I have setup a Core Data app with the usual boilerplate code, and the RootViewController initializes the FRC by calling this: - (NSFetchedResultsController *)fetchedResultsController { if (__fetchedResultsController != nil) { return __fetchedResultsController; } // configure the fetchRequest, sectionKey and cacheName __fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest: fetchRequest managedObjectContext: self.managedObjectContext sectionNameKeyPath: sectionKey

Core Data Multithreading: Code Examples

孤者浪人 提交于 2019-12-22 10:54:57
问题 I've been having problems with my multi-threaded Core Data enabled app, and I figured I should take a hard look at what I'm doing and how. Please let me know if the following should work. I have a singleton DataManager class that handles the Core Data stuff. It has a property managedObjectContext that returns a different MOC for each thread. So, given NSMutableDictionary *_threadContextDict (string thread names to contexts) and NSMutableDictionary *_threadDict (string thread names to threads)

How to keep a child NSManagedObjectContext up to date when using bindings

北慕城南 提交于 2019-12-22 10:45:06
问题 I have a NSManagedObjectContext set to have a NSPrivateQueueConcurrencyType which I'm using most of the time across my app. As well as this I created a child MOC with NSMainQueueConcurrencyType for use with cocoa bindings (I hear that bindings don't work with private queue MOCs). I have bound some ObjectController s and an ArrayController to this child context. I very much want to keep the child on the main queue rather than swapping the MOC queue types. When I make changes to the bound

Debugging in XCode: Exception Breakpoints

半城伤御伤魂 提交于 2019-12-22 05:45:09
问题 I'm debugging a random SIGTRAP crash right now that just happens in the background. It's probably something that has to do with an NSManagedObjectContext somewhere. Besides that, I'm trying to debug it using an exception breakpoint to at least find out where it's originating from. The only problem is that the crash/breakpoint occurs in a 0 objc_exception_throw, which is no help to me. The data I get back looks like this: libobjc.A.dylib`objc_exception_throw: 0x32a3a960: push {r4, r5, r6, r7,

Executing Core Data saving on a background thread?

纵然是瞬间 提交于 2019-12-22 00:41:54
问题 I've got a button which marks a selected entry in a Core Data SQLite as a "Favourite", meaning I'm just flipping a BOOL for that index from off to on. Currently, when I do this, I call save on the managedObjectContext , which takes maybe 500ms, perhaps a little more, according to Instruments. I have some code that executes at the same time which triggers a nifty little particle explosion ("Hooray, a favourite!"), but I'm running into an issue where that explosion is delayed until after the

[ controllerWillChangeContent:]: message sent to deallocated instance

本秂侑毒 提交于 2019-12-21 20:51:02
问题 I am having a problem with my ipad app. I've got a view that is accessed in 2 ways, if i go in one way it works perfectly. If I go in through another though, it crashes when saving the context. I suspect it is something in the parent (orders by customer) -- I get a zombie with the message: [OrdersByCustomer controllerWillChangeContent:]: message sent to deallocated instance 0x10102020 when I run it through intstruments with Zombies I get: # Category Event Type RefCt Timestamp Address Size

How to share an entity between two different core data models

吃可爱长大的小学妹 提交于 2019-12-21 17:47:04
问题 I'm wondering how to share an entity between two different core data models? For example, I have a " Universe " model which describes a " WorldData " with its " CountryData ". And in another hand, I have a "Population" model which describes a " HumanData " with its " CountryData ". I definitely want to keep my models separated. Thanks in advance. 回答1: Have you checked the Core Data Guide? Managing relationships between entities is pretty basic. If you want to manage a relationship between

NSUndoManager, Core Data and selective undo/redo

核能气质少年 提交于 2019-12-21 10:46:11
问题 I'm working on a core data application that has a rather large hierarchy of managed objects similar to a tree. When a base object is created, it creates a few child objects which in turn create their own child objects and so on. Each of these child objects may gather information using NSURLConnections. Now, I'd like to support undo/redo with the undoManager in the managedObjectContext. The problem is, if a user creates a base object, then tries to undo that action, the base object is not

Saving Single CoreData Entity (Not the Whole Context) While Keeping NSFetchedResultController Functionality

不想你离开。 提交于 2019-12-21 04:06:43
问题 Phew, sorry for the long title. I have a single Managed Object Context where I am storing songs derived from two different locations. I get some of the songs from the persistent storage on the phone (using Core Data), and I pull some of the songs from an online database. Both of the songs are of the same MananagedObject subclass. I would like both of these songs to be in a single context because I would like them both to show up on a table view connected with an NSFetchedResultsController.