nsmanagedobjectcontext

NSUndoManager, Core Data and selective undo/redo

做~自己de王妃 提交于 2019-12-04 05:47:53
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 removed. Instead, one or more of the child objects may be removed. Obviously this type of action is

Error creating a separate NSManagedObjectContext

你离开我真会死。 提交于 2019-12-04 05:16:03
问题 Before getting into my issue, please have a look at this image. Here is the actual data model: I retrieve a set of Records from a web API, create objects out of them, save them in core data and display them in the Today view. By default these records are returned for the current date. The user can tap on Past button to go to a separate view where he can choose a past or future date from a date picker view and view Records for that selected date. This means I have to call the API again passing

How to Get Path of MOMD File in Core Data

社会主义新天地 提交于 2019-12-04 02:04:11
问题 Ey guys, I have seen this question and have used self.managedObjectContent= [NSManagedObjectModel mergedModelFromBundles:nil]; in my code, however, I would like to be able to print a filepath via NSLog to console with the full path of the momd file. Problem is I don't know how to go about extracting the path to the MOMD resource using objective c, when I try logging managedObjectContent to console it ends up printing very lengthy arcane data that I don't even care about. So how would I go

Saving NSManagedObjectContext with NSPrivateQueueConcurrencyType

ⅰ亾dé卋堺 提交于 2019-12-03 21:45:06
Im currently learning how to use core-data in a multithreaded environment; I therefore created a small project with two NSManagedObjectContext : A main NSManagedObjectContext with NSMainQueueConcurrencyType for reads and its child NSManagedObjectContext with NSPrivateQueueConcurrencyType for create/update/delete operations. It has often been said that saving an NSManagedObjectContext with NSPrivateQueueConcurrencyType should be done through performBlock: like so: [context performBlock:^ { Book *mutableBook = [self getMutableVersionOfBook:book]; [context deleteObject:mutableBook]; [context save

Take action when two separate NSFetchRequests have both completed

≯℡__Kan透↙ 提交于 2019-12-03 20:46:50
I'm using a remote database with Core Data and when I execute the following fetch requests, depending on the internet connection, it can take some time. I'd like to monitor these two requests and, when they are complete -- whether successful or failed -- I'd like to trigger another method. FetchRequest 1: [self.managedObjectContext executeFetchRequest:fetchRequest1 onSuccess:^(NSArray *results) { //Succcess [self.refreshControl endRefreshing]; } onFailure:^(NSError *error) { [self.refreshControl endRefreshing]; }]; FetchRequest 2: [self.managedObjectContext executeFetchRequest:fetchRequest2

New thread + NSManagedObjectContext

风流意气都作罢 提交于 2019-12-03 20:12:12
I'm trying to separate my application work when there is a bigger work to do to optimize performance. My problem is about a NSManagedObjectContext used in another thread than the main one. I'm calling: [NSThread detachNewThreadSelector:@selector(test:) toTarget:self withObject:myObject]; On the test method there are some stuff to do and I have a problem here: NSArray *fetchResults = [moc executeFetchRequest:request error:&error]; Here is my test method: -(void) test:(MyObject *)myObject{ @autoreleasepool { //Mycode } } The second time I call the test method, my new thread is blocked when the

Get NSManagedObjectContext when using Storyboard

六月ゝ 毕业季﹏ 提交于 2019-12-03 17:24:53
问题 The objective is to get the current NSManagedObjectContext in order to work with Core Data. In iOS 4.3 I set the UINavigationController's delegate to be the AppDelegate like so (in AppDelegate.m): self.navigationController.delegate = self; and I could do something like this (wherever I needed the context): NSManagedObjectContext *context = [self.navigationController.delegate performSelector:@selector(managedObjectContext)]; Now, in iOS 5, I am using a Storyboard and I'm having a difficult

iOS RestKit can not save local entity to database

淺唱寂寞╮ 提交于 2019-12-03 16:40:48
问题 I am using RestKit 0.20 to parse JSON data and save to database. THere is a mapped entity SchoolClass, which is handled by RestKit and saves fine. I have another entity called MyClass, which stores the classes I have selected. This one is only local on the device. Here is the code I create and save the MyClass entity NSManagedObjectContext *managedObjCtx = [RKManagedObjectStore defaultStore].mainQueueManagedObjectContext; MyClass* course = [managedObjCtx insertNewObjectForEntityForName:@

performBlockAndWait creates deadlock

一世执手 提交于 2019-12-03 15:55:34
I am writing a function that performs some CoreData stuff. I want the function to return only after all the CoreData operations have executed. The CoreData stuff involves creating an object in a background context, then doing some more stuff in the parent context: + (void) myFunction NSManagedObjectContext *backgroundContext = [DatabaseDelegate sharedDelegate].backgroundContext; [backgroundContext performBlockAndWait:^{ MyObject *bla = create_my_object_in:backgroundContext; [backgroundContext obtainPermanentIDsForObjects:[[backgroundContext insertedObjects] allObjects] error:nil];

CoreData: Fetching an Object from an unsaved Context

跟風遠走 提交于 2019-12-03 15:04:35
after I insert a ManagedObject into a context I'd like to fetch it later but before saving the context (I'd save after all objects are inserted). It appears that querying the context later with a fetch concerning those objects returns nothing if the context wasn't previously saved. Is there a way to save only in the end ?(I guess i can save my objects in an array or dictionary and query that but i thought coredata would do this for me) Try this: [myFetchRequest setIncludesPendingChanges:YES]; From the documentation : Sets if, when the fetch is executed, it matches against currently unsaved