nsmanagedobjectcontext

How to get managedObjectContext for viewController other than getting it from appDelegate?

天涯浪子 提交于 2019-11-26 22:21:16
问题 Recently I came to know that "You really shouldn't be calling down to the AppDelegate to get the managed object context". Apple also has put this recommendation into their documentation here. It goes like this : A view controller typically shouldn’t retrieve the context from a global object such as the application delegate—this makes the application architecture rigid. Neither should a view controller create a context for its own use (unless it’s a nested context). This may mean that

Changing a managed object property doesn't trigger NSFetchedResultsController to update the table view

a 夏天 提交于 2019-11-26 19:53:52
I have a fetchedResultsController with a predicate, where "isOpen == YES" When calling for closeCurrentClockSet , I set that property to NO . Therefore, it should no longer appear on my tableView. For Some Reason, this is not happening. Can someone help me figure this out please? -(void)closeCurrentClockSet { NSPredicate * predicate = [NSPredicate predicateWithFormat:@"isOpen == YES"]; NSArray *fetchedObjects = [self fetchRequestForEntity:@"ClockSet" withPredicate:predicate inManagedObjectContext:[myAppDelegate managedObjectContext]]; ClockSet *currentClockSet = (ClockSet *)fetchedObjects

Core Data nested managed object contexts and frequent deadlocks / freezes

允我心安 提交于 2019-11-26 19:09:11
问题 I have a problem that is almost identical to the problem described by this person here, but it hasn't get answered: http://www.cocoabuilder.com/archive/cocoa/312683-core-data-nested-managed-object-contexts-and-frequent-deadlocks.html#312683 Here is the problem: I have a parent MOC setup with NSPrivateQueueConcurrencyType and a persistent store coordinator set, it has a child MOC setup with NSMainQueueConcurrencyType. The idea being most of the long hard work and saves can be done on the

Core Data background context best practice

有些话、适合烂在心里 提交于 2019-11-26 18:04:06
I have a large import task I need to do with core data. Let say my core data model look like this: Car ---- identifier type I fetch a list of car info JSON from my server and then I want to sync it with my core data Car object, meaning: If its a new car -> create a new Core Data Car object from the new info. If the car already exists -> update the Core Data Car object. So I want to do this import in background without blocking the UI and while the use scrolls a cars table view that present all the cars. Currently I'm doing something like this: // create background context

Fetching selected attribute in entities

主宰稳场 提交于 2019-11-26 16:57:44
问题 I have a core-data entity with several attributes, and I want a list of all the objects in one attribute. My code looks like this: let appDel:AppDelegate = UIApplication.sharedApplication().delegate as AppDelegate let context:NSManagedObjectContext = appDel.managedObjectContext! let sortDesc = NSSortDescriptor(key: "username", ascending: true) let fetchReq = NSFetchRequest(entityName: "Identities") fetchReq.sortDescriptors = [sortDesc] fetchReq.valueForKey("username") let en =

How do I copy or move an NSManagedObject from one context to another?

删除回忆录丶 提交于 2019-11-26 15:05:48
问题 I have what I assume is a fairly standard setup, with one scratchpad MOC which is never saved (containing a bunch of objects downloaded from the web) and another permanent MOC which persists objects. When the user selects an object from scratchMOC to add to her library, I want to either 1) remove the object from scratchMOC and insert into permanentMOC, or 2) copy the object into permanentMOC. The Core Data FAQ says I can copy an object like this: NSManagedObjectID *objectID = [managedObject

Implementing Fast and Efficient Core Data Import on iOS 5

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-26 11:44:28
问题 Question : How do I get my child context to see changes persisted on the parent context so that they trigger my NSFetchedResultsController to update the UI? Here\'s the setup: You\'ve got an app that downloads and adds lots of XML data (about 2 million records, each roughly the size of a normal paragraph of text) The .sqlite file becomes about 500 MB in size. Adding this content into Core Data takes time, but you want the user to be able to use the app while the data loads into the data store

Core Data: Do child contexts ever get permanent objectIDs for newly inserted objects?

青春壹個敷衍的年華 提交于 2019-11-26 09:28:06
问题 I have an app with two managed object contexts setup like this: Parent Context: NSPrivateQueueConcurrencyType, linked to the persistent store. Main Context: NSMainQueueConcurrencyType, child of Parent Context. When insert a new managed object to the main context, I save the main context and then the parent context like this: [context performBlockAndWait:^{ NSError * error = nil; if (![context save: &error]) { NSLog(@\"Core Data save error %@, %@\", error, [error userInfo]); } }];

Changing a managed object property doesn't trigger NSFetchedResultsController to update the table view

拜拜、爱过 提交于 2019-11-26 07:27:38
问题 I have a fetchedResultsController with a predicate, where \"isOpen == YES\" When calling for closeCurrentClockSet , I set that property to NO . Therefore, it should no longer appear on my tableView. For Some Reason, this is not happening. Can someone help me figure this out please? -(void)closeCurrentClockSet { NSPredicate * predicate = [NSPredicate predicateWithFormat:@\"isOpen == YES\"]; NSArray *fetchedObjects = [self fetchRequestForEntity:@\"ClockSet\" withPredicate:predicate

Core Data background context best practice

回眸只為那壹抹淺笑 提交于 2019-11-26 06:53:04
问题 I have a large import task I need to do with core data. Let say my core data model look like this: Car ---- identifier type I fetch a list of car info JSON from my server and then I want to sync it with my core data Car object, meaning: If its a new car -> create a new Core Data Car object from the new info. If the car already exists -> update the Core Data Car object. So I want to do this import in background without blocking the UI and while the use scrolls a cars table view that present