I need to fire fetch request controller after finish the updating. Is their any method to control this.
Reason is some parent entity have child entity called "Image". This use for store the image. This images are download separately.
Because of this reason i can't get images when fetch request controller fire(image download not finished).
Ask the fetchedResultsController to refetch by calling performFetch.
NSError *error;
[self.fetchedResultsController performFetch:&error];
Related
Before anyone suggests, we are using one managedObjectContext for [context save:&error];
We are saving a new object in Core Data with iOS5.
The issue is, the first time we save a new object, NSManagingContextDidSaveChangesNotification fires and the [[notification userInfo] objectForKey:NSUpdatedObjectsKey] gives back an unpopulated object. In iOS6, objectForKey:NSUpdatedObjectsKey is populated.
Afterwards when we save objectForKey:NSUpdatedObjectsKey is populated.
The context we are always using is [[UIApplication sharedApplication] delegate].mainDocument.managedObjectContext.
So the issue is, the first time [context save:&error] is called, nothing is saved to the db. But it has been saved to the object, so the next time [context save:&error] is called it gets put in the db.
Does anyone have any info on this. I've heard tell of bugs in CoreData in iOS5 , so if anyone has any advice we would appreciate it.
Check these items in the given order:
Make sure the object is already populated when you save it the first time (e.g. NSLog).
Make sure you query the notifications's userInfo properly.
Make sure at this point that the physical database does not contain the proper information (e.g. via sqlite3 command line tool)
Make sure you output the correct object whenever you check if it is populated or not.
In my iPhone/iPad app I'm handling all network and web-API-requests through a "APIManager" (singleton, created in AppDelegate).
Currently the APIManager contains only one single ASINetworkQueue, to which APIRequests (subclass of ASIHTTPRequest) are added and executed. In the userInfo of each APIRequest some additional information to handle the request is added (like whether the response should be parsed into Core Data - and if so, which entity - or not).
When the user moves from one view (ViewA) to another (ViewX), I would like to have the possibility to cancel all the requests that ViewA have asked the APIManager to perform, while letting others continue.
Is there some functionality to find a certain request in a ASINetworkQueue (or NSOperationQueue) and send a cancellation message to it? Maybe using parameters added to the userInfo of the request?
Thanks in advance!
[queue operations] will return an NSArray of items in the queue, which you can then iterate and call 'cancel' on any you like.
Something like:
for (ASIHTTPRequest *req in [queue operations])
{
if (shouldCancel(req))
[req cancel];
}
In my iPhone app, I have an NSFetchedResultsController showing User objects in a UITableView. The User Objects have 0-many Log objects. A summary of the Log objects are shown together with their User object in the UITableView.
My app uses a tab bar, so user input in the logging tab require that the user tab's NSFetchedResultsController is triggered to reload.
So far I do it by writing to the User object:
log.user = nil;
log.user = [User current]; // Same as before. Just triggering a reload.
NSError *error = nil;
[myManagedObjectContext save:&error];
This works fine, but seems a bit like a hack.
Is there a better way to do this? Like specifying that changes in the Log object should propagate to the User object too?
[myFetchedResultsController performFetch:&error];
But why would you want to do this? It should only reload when there is new data for it to fetch. If there is new data then a save of the NSManagedObjectContext is the right action.
What is your underlying goal?
Any idea why
//should save the object context.
NSError *error;
if (![managedObjectContext save:&error]) {
NSLog(#"SAVE ERROR");
}
when implemented in a view controller(accessed via a drill down tableview) won't properly save the information? I am passing the moc from the beginning (rootview hands off to tableview, tableview recursively passes it to itself until calls uiview) and any additions I do show up in the table if I pop/push the tableview(unfortunately reloadData in viewWillAppear doesn't want to update it).
Should I be passing the managedObject instead and fetching the context from that?
Since I was manually creating the sqlite entries in the code on load, I was also manually deleting it in the persistentStoreCoordinator each time the program started. Unfortunately, I forgot about that aspect.
I'm new to this Core Data business.
I got a UITableViewController hooked up with a NSFetchedResultsController. In viewDidLoad, I fire a request to get necessary data from the server, then use [self.fetchedResultsController performFetch:&error] to update the table view. All works fine until that point.
Now I want to move the data fetching stuff to another thread, so after the app received a NSArray object from the server, it performs the didFinishFetchingItems selector on the main thread. In that selector, I save the NSArray to the Core Data store and have the fetchedResultsController perform a fetch. No data show up, although a NSLog reveals that the data is still there (e.g. [[fetchedResultsController fetchedObjects] count] returns 100). I have to put a [self.tableView reloadData] at the end of the method to refresh the table view manually.
My question is: What have I done wrong? Why did I need to do the table view refreshing manually?
You should not touch your NSFetchedResultsController in a non-main thread, that is not a thread-safe operation.
If you are having a long delay on fetching then you need to do a background fetch using a separate NSManagedObjectContext. If you perform a separate fetch in the background it will load the data into cache and then the NSFetchedResultsController will hit the cache instead of disk, speeding up retrieval on the main thread.
You do not need to refresh anything manually; fetchedResultsController does that for you.
What you need to do is to implement NSFetchedResultsControllerDelegate for some object, and set that object as the delegate for your fetchedresultscontroller.
See this about what you need to implement. If your model is simple, you can pretty much copy-paste that code into your delegate and everything works.
The important thing is to keep both the resultscontroller and other pieces of code working against the same managed object context. This is how the resultscontroller can pick up the changes. But, in Core Data guide, there are some caveats about multithreading, so make sure you have your threading bases covered and then all works.