nsmanagedobjectcontext

performBlockAndWait On Child Context with Private Queue Deadlocks Parent on iOS 7

半腔热情 提交于 2019-12-05 06:50:52
I have two NSManagedObjectContext s named importContext and childContext . childContext is the child of importContext and both of them are NSPrivateQueueConcurrencyType . To keep things off the main thread, I'm doing a bunch of work on the importContext 's queue. This work involves lots of fetches and saves, so it's convenient to wrap the whole thing inside a performBlockAndWait: of the importContext (it does need to by a synchronous operation because the code I have after the performBlockAndWait depends on its results). At some point during this work, I might need to create new managed

Debugging in XCode: Exception Breakpoints

送分小仙女□ 提交于 2019-12-05 06:36:52
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, lr} // breakpoint stops here 0x32a3a962: add r7, sp, #12 0x32a3a964: mov r4, r0 0x32a3a966: movs r0,

Crashing on saving a managedObjectContext, with 'NSInvalidArgumentException', but only sporadically

喜夏-厌秋 提交于 2019-12-05 05:19:07
I keep getting crashes from a save: command on a managedObjectContext. It doesn't even fulfill the NSLog statement so I don't see the unresolved error statement, so I can't figure out what the problem might be. It doesn't happen every time, but only sporadically. Here's the code (which basically wants to increment a counter): if ([[managedObject valueForKey:@"canSee"]boolValue]){ int read = [[managedObject valueForKey:@"timesRead"] intValue] +1; [managedObject setValue:[NSNumber numberWithInt:read] forKey:@"timesRead"]; NSError *error; if (![resultsController.managedObjectContext save:&error])

New thread + NSManagedObjectContext

房东的猫 提交于 2019-12-05 02:40:56
问题 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{

performBlockAndWait creates deadlock

纵然是瞬间 提交于 2019-12-04 23:34:19
问题 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

CoreData: Fetching an Object from an unsaved Context

柔情痞子 提交于 2019-12-04 23:33:06
问题 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) 回答1: Try this: [myFetchRequest setIncludesPendingChanges

How to test Core Data properly in Swift

纵然是瞬间 提交于 2019-12-04 22:00:53
问题 There are quite a few subjects on this already, but I have yet to find a solution that is workable for Swift (Xcode 6.2). To test Core Data backed classes in Swift, I generate new Managed Object Contexts that I then inject into my classes. //Given let testManagedObjectContext = CoreDataTestComposer.setUpInMemoryManagedObjectContext() let testItems = createFixtureData(testManagedObjectContext) as [TestItem] self.itemDateCoordinator.managedObjectContext = testManagedObjectContext //When let

Core Data concurrency queue style MOC getters thread safety

試著忘記壹切 提交于 2019-12-04 21:20:38
问题 I am really confused by the following paragraph straight from the NSManagedObjectContext documentation: Setter methods on queue-based managed object contexts are thread-safe. You can invoke these methods directly on any thread. The big question is setters methods on the ManagedObjectContext but NOT in the ManagedObjects owned by this context? or is it on both?. Specifically if for a private queue MOC object something like this: [privateContext setPersistentStoreCoordinator:self

Unable to pass NSManagedObjectContext to my view controller

那年仲夏 提交于 2019-12-04 20:27:20
Ok, I may be in well over my head here, but suspect I am missing something quite fundamental. I have searched on stack and other forums for help on finding a solution. I've tried all the solutions I have found but none work for my situation and I cannot see what I am missing. I have created a CoreData app. All works fine in reading and writing data to the CoreData store using NSManagedObjectContext within my appDelegate. I have checked to see if the NSManagedObjectContext is set in my AppDelegate and it is. After passing it to my only viewController I check to see if it is set and it isn't. So

How to assign a managed object context to the application delegate in iOS?

我怕爱的太早我们不能终老 提交于 2019-12-04 19:47:36
I created an iOS project and a managed object model ( Model.xcdatamodeld ) with one entity. In application:didFinishLaunchingWithOptions: I want to test if the managed object model exists, however I am getting nil . Do I have to do something special to create the managed object context after I create the managed object model? Any suggestions on what I may be doing wrong? This is the interface @interface AppDelegate : UIResponder <UIApplicationDelegate> { } @property (nonatomic, strong, readonly) NSManagedObjectContext *managedObjectContext; @property (nonatomic, strong, readonly)