nsfetchedresultscontroller

Locations in Core Data sorted by distance via NSFetchedResultsController?

浪尽此生 提交于 2019-11-29 06:55:16
I have a set of entity objects in my iOS Core Data database that describe something at a location. Let's call the entity Location. I have implemented this by having two attributes on Location that refer to the location - latitude and longitude, both doubles. There are other elements, like name. I am using a NSFetchedResultsController to bind the entities to a UITableViewController. What I would like to do is have the results sorted by distance to a given CLLocationCoordinate2D. In an really ideal scenario, I'm able to refresh that list to recalculate the sort based on a new location. Therefore

iOS UITableView sections with fetchedResultsController confusion

☆樱花仙子☆ 提交于 2019-11-29 04:03:38
I have an entity being displayed in a table view in just one section. The entity has two attributes, workoutName and trainingLevel . Both are of string type. Training level consists of the 3 types: 1, 2, 3. (trainingLevel = (Integer 16 or String Type? Which would be ideal?) I would like to split the table into three sections, each section containing entries for the corresponding training level. How do I do this? The code I am currently using is below: - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { // Return the number of sections. return 1; } - (NSInteger)tableView:

UITableViewRowAnimation is ignored

纵饮孤独 提交于 2019-11-29 02:35:38
I'm using NSFetchedResultsController to populate my table. The data in my table is sorted according to the timestamp in the ascending order (latest message at the bottom). More data is loaded via "infinite scroll" to the top: e.g. when user scrolls past the top, more messages are loaded. My NSFetchedResultsControllerDelegate is defined as usual, as recommended in the apple documentation: new rows are inserted via - (void)controller:(NSFetchedResultsController*)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath*)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath

NSFetchedResultsController: Fetch in a background thread

我只是一个虾纸丫 提交于 2019-11-29 02:20:58
I have a more or less basic UITableViewController with a NSFetchedResultsController . The UITableViewController is pushed onto the navigationController's stack. But the push animation isn't smooth because the fetch of NSFetchedResultsController is performed on the main thread, and therefore blocks the UI. My question is: How can I perform the fetch of the NSFetchedResultsController in a background thread to keep the animation smooth? The NSFetchedResultsController and the delegate methods look like this: - (NSFetchedResultsController *)fetchedResultsController { if (_fetchedResultsController !

NSFetchedResultsController doesn't show updates from a different context

醉酒当歌 提交于 2019-11-29 00:45:30
问题 I have an NSFetchedResultsController and a few operations updates managed objects on separate threads via NSOperationQueue . The FRC (with its predicate) looks like this: - (NSFetchedResultsController*)fetchedResultsController { if(fetchedResultsController) return fetchedResultsController; NSManagedObjectContext* mainContext = [self managedObjectContext]; NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; [fetchRequest setEntity:[NSEntityDescription entityForName:@"Check"

Core Data Table View Section Sort by weekdays using NSSortDescriptor

邮差的信 提交于 2019-11-29 00:41:29
I'm currently trying to sort my array of objects into day order so they can be grouped in the correct order i.e. Monday, Tuesday, Wednesday then by start time. Only problem is I can't figure out how to do this, my code currently looks like this: Which sorts alphabetically then by time: NSString *sectionKey = nil; switch (tab) { case kByWeekA: { NSSortDescriptor *sortDescriptor1 = [[NSSortDescriptor alloc] initWithKey:@"day" ascending:NO]; NSSortDescriptor *sortDescriptor2 = [[NSSortDescriptor alloc] initWithKey:@"starttime" ascending:YES]; NSArray *sortDescriptors = [[NSArray alloc]

Changing the Sorting in an NSFetchedResultsController on the fly

被刻印的时光 ゝ 提交于 2019-11-28 22:47:20
问题 I'm trying to change the sorting in a NSFetchController on the fly, by some sort of segmented control. To either sort A->Z Z->A type thing. What do I have to do to do this? I'm following Jeff Lamarche's example here: Here Do I need to make a new NSFetchedResultsController and then set it, or do I just make a new NSFetchRequest and do fetchedResultController.fetchRequest = newFetchRequest and then my table will automatically update? 回答1: I was stuck with the same problem and I could fix it

(NSFetchedResultsController): couldn't read cache file to update store info timestamps

谁都会走 提交于 2019-11-28 22:11:38
问题 I upgraded my project to Xcode 8. Now, I'm getting this error log with Xcode 8 and iOS 10 combination. Setting the cacheName to nil in the below code seems fix it. NSFetchedResultsController *frc = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:NULL cacheName:@"myCache"]; What should I do to get rid of this error log and use cache in my FRC? 回答1: This error should not be ignored because it can cause app

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'no object at index 3 in section at index 0'

一世执手 提交于 2019-11-28 18:27:38
Hi I'm having a hard time fixing this error. Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'no object at index 3 in section at index 0' That error exist when I delete all my Entity in coredata and refetch it. CALL API self.fetchedResultsController = nil; [NSFetchedResultsController deleteCacheWithName:nil]; [api requestForMenuCategory:@"details" managedObjectContext:self.managedObjectContext delegate:self]; EXECUTE WHEN API IS DONT FETCHING DATA if (![self.fetchedResultsController performFetch:&error]) { NSLog(@"%@",[error description]); } else{ NSLog(@

NSFetchedResultsController crashing on performFetch: when using a cache

孤街醉人 提交于 2019-11-28 16:38:15
问题 I make use of NSFetchedResultsController to display a bunch of objects, which are sectioned using dates. On a fresh install, it all works perfectly and the objects are displayed in the table view. However, it seems that when the app is relaunched I get a crash. I specify a cache when initialising the NSFetchedResultsController, and when I don't it works perfectly. Here is how I create my NSFetchedResultsController: - (NSFetchedResultsController *)results { // If we are not nil, stop here if