nsfetchedresultscontroller

Locations in Core Data sorted by distance via NSFetchedResultsController?

孤人 提交于 2019-11-28 00:20: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

Sorting on 'transient' fields with NSFetchedresultController

▼魔方 西西 提交于 2019-11-28 00:01:10
Is there a way to use a 'transient' field or something like that and in some way sort accordingly with a NSFetchedResultsController. I want to do the following: I have location of places in a database. When a person opens the list, I want to show the nearest place on top, an then sort accordingly to distance. But clearly,this depends on the users location, so I cannot use a static field. I was hoping to use a transient field, as you can use for the section headers. Is there anybody who can give a solution or workaround for this situation? You cannot use a transient property in a fetch request

Core Data NSPredicate with to-Many Relationship

南楼画角 提交于 2019-11-27 22:34:02
I have two Entities in CoreData called User and Coupon, they are in Many-to-Many relationship. I wanted to fetch for all Coupons except those owned by user.userId = 1, where userId is NSString. I used: [NSPredicate predicateWithFormat:@"NOT(ANY couponOwners.userId = %@)", @"4"]; to be the predicate of my fetchedResultsController but not filtering with correct results. One of the User in couponOwners of the Coupon is still having userId = 4. Could somebody please help? I have been stuck for quite a while. Thanks in advance. Core Data predicates with "NOT ANY" do not work (that seem to be a Core

NSRangeException exception in NSFetchedResultsChangeUpdate event of NSFetchedResultsController

五迷三道 提交于 2019-11-27 22:27:30
I have a UITableView that uses an NSFetchedResultsController as data source. The core data store is updated in multiple background threads running in parallel (each thread using it's own NSManagedObjectContext ). The main thread observes the NSManagedObjectContextDidSaveNotification notification and updates it's context with mergeChangesFromContextDidSaveNotification: . Sometimes it happens that the NSFetchedResultsController sends an NSFetchedResultsChangeUpdate event with an indexPath that does not exist anymore at that point. For example: The result set of the fetched results controller

Core Data backed UITableView with indexing

余生颓废 提交于 2019-11-27 20:20:38
问题 I am trying to implement a Core Data backed UITableView that supports indexing (eg: the characters that appear down the side, and the section headers that go with them). I have no problems at all implementing this without Core Data using: - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section; - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView; I also have no problem implementing a UITableView that is backed by Core Data without using the

NSFetchedResultsController with search

谁都会走 提交于 2019-11-27 19:57:00
问题 What is the best practice to filter the NSFetchedResultsController data? do i need to re-initialize it every time the searchbar's text changes? I am using a UISearchDisplayControllers and i'm implementing: - (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString; Thx. 回答1: How is Guy's answer code any different from the question? As far as I can guess, the filterContentForSearchText:scope method is called by the

Core Data - How to fetch an entity with max value property

十年热恋 提交于 2019-11-27 19:18:15
I have a entity Person with a property personId (personId is unique) How can I fetch the Person with the max personId? (I want to fetch the person itself not the value of the property) You set the fetchLimit to 1 and sort by personId in descending order. E.g.: NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"Person"]; fetchRequest.fetchLimit = 1; fetchRequest.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"personId" ascending:NO]]; NSError *error = nil; id person = [managedObjectContext executeFetchRequest:fetchRequest error:&error].firstObject;

Core Data nested managed object contexts and frequent deadlocks / freezes

纵然是瞬间 提交于 2019-11-27 17:43:21
I have a problem that is almost identical to the problem described by this person here, but it hasn't get answered: http://www.cocoabuilder.com/archive/cocoa/312683-core-data-nested-managed-object-contexts-and-frequent-deadlocks.html#312683 Here is the problem: I have a parent MOC setup with NSPrivateQueueConcurrencyType and a persistent store coordinator set, it has a child MOC setup with NSMainQueueConcurrencyType. The idea being most of the long hard work and saves can be done on the private MOC freeing the main thread from blocking the UI. Unfortunately I seem to be running into a couple

Is there a way to instantiate a NSManagedObject without inserting it?

独自空忆成欢 提交于 2019-11-27 17:06:28
I have a user interface to insert a Transaction. once the user clicks on a plus he gets the screen and i want to instantiate my Core Data NSManagedObject entity let the user work on it. Then when the user clicks on the Save button i will call the save function. so down to code: transaction = (Transaction *)[NSEntityDescription insertNewObjectForEntityForName:@"Transaction" inManagedObjectContext:self.managedObjectContext]; //even if i dont call save: its going to show up on my table [self.managedObjectContext save:&error] P.S i am using an NSFetchedResultsController on that table and I see

UITableViewRowAnimation is ignored

旧时模样 提交于 2019-11-27 16:53:50
问题 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