nsmanagedobjectcontext

Performance of NSManagedObjectContext save degrades dramatically

空扰寡人 提交于 2020-01-02 01:59:10
问题 I am having issues with a CoreData-based iOS app when it tries to build the initial DB from data sent from the server. Basically, the server sends down 1MB chunks of objects (about 3,000 per chunk), and the iOS client deserializes them and writes them into disk. What I'm seeing is that everything is going pretty well for about the first 8 chunks (out of 44), then performance drops off dramatically and each chunk starts taking longer and longer, as in the image below. Pretty much all the time

How to handle saving on child context but the objected is already deleted in parent context?

こ雲淡風輕ζ 提交于 2020-01-01 17:14:15
问题 I have core data nested contexts setup. Main queue context for UI and saving to SQLite persistent store. Private queue context for syncing data with the web service. My problem is the syncing process can take a long time and there are the chance that the syncing object is deleted in the Main queue context. When the private queue is saved, it will crash with the "Core Data could not fulfill faulted" exception. Do you have any suggestion on how to check this issue or the way to configure the

Saving NSManagedObjectContext with NSPrivateQueueConcurrencyType

守給你的承諾、 提交于 2020-01-01 07:13:35
问题 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:^ {

Take action when two separate NSFetchRequests have both completed

守給你的承諾、 提交于 2020-01-01 07:01:12
问题 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

How to remove a core data persistent store

痴心易碎 提交于 2020-01-01 01:00:07
问题 I need to delete my persistent store (doing it object by object is not practical because I have over 100,000 objects). I've tried this: - (IBAction)resetDatabase:(id)sender { NSPersistentStore* store = [[__persistentStoreCoordinator persistentStores] lastObject]; NSError *error = nil; NSURL *storeURL = store.URL; // release context and model [__managedObjectContext release]; [__managedObjectModel release]; __managedObjectModel = nil; __managedObjectContext = nil; [__persistentStoreCoordinator

Can't create externalDataReference interim file

时光毁灭记忆、已成空白 提交于 2019-12-30 14:07:11
问题 I use Core Data in my iOS project. I am using multiple contexts in the following way. I have a persisent store context that operates on a private queue and stores changes to the persistent store. I have a main queue context that is the child of persistent store context . All of the FRC s in my app use this context. And finally, if I have to do some changes that I want to save in a batch, I create and use new NSManagedObjectContext s that are children of the main queue context. So I have a

filtering NSFetchedResultController via searchBar without loading base pauses?

泪湿孤枕 提交于 2019-12-25 08:18:39
问题 i try to create search in big Core Data base (32 thousand objects) but when i added some text to the UISearchBar i have some lags (because my base is updating with new search Predicate) how to fix this? how can i update my base in background thread? fetchedResultController code lazy var context: NSManagedObjectContext = { let appDelegate = (UIApplication.shared.delegate as? AppDelegate) let context = appDelegate!.managedObjectContext return context//appDelegate!.managedObjectContext }() lazy

Core Data context and singleton data controller

有些话、适合烂在心里 提交于 2019-12-25 05:59:09
问题 I have a singleton data controller to hold an array of objects. See for example bananas question for my solution: singelton dataController banansArray Now I want to save the array of bananas to persistant state. This core data tutorial: core data - store images have given me a good general understanding of Core Data and I was able to include it in my application before changing my data Controller to singleton. Now what is best? Do I need to move the generated Core Data stack within the

passing ManagedObjectContext via prepareforsegue

天涯浪子 提交于 2019-12-25 05:24:06
问题 First of all, this is my basic setup. I'm trying to pass a NSManagedObjectContext (MOC) from my AppDelegate to the selected custom ViewController. First, in "AppDelegate.m", I do: UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController; FirstTableViewController *tableVC = (FirstTableViewController *)navigationController.topViewController; tableVC.managedObjectContext = self.managedObjectContext; to pass the MOC to the tableViewController which

How to prevent temporaryContext run concurrently with migratePersistentStore

北慕城南 提交于 2019-12-25 04:50:13
问题 I have a code part where I call migratePersistentStore and I want to prevent any temporaryContext to do anything in the same time, how? My idea is based on a semaphore and a dispatch_group . code A: dispatch_group_wait(dgLoadMain, DISPATCH_TIME_FOREVER) dispatch_semaphore_wait(semaLoadMain, DISPATCH_TIME_FOREVER) mainMOC!.performBlockAndWait({ mainMOC!.persistentStoreCoordinator!.migratePersistentStore(/* ... */) }) dispatch_semaphore_signal(semaLoadMain) code B: dispatch_group_enter