nssortdescriptor

NSFetchedResultsController: The fetched object at index x has an out of order section name

半世苍凉 提交于 2019-12-06 16:09:29
I have three sections in my tableView: Today Upcoming Past When the app launches, the view controller that's launched has an NSFetchedResultsController. If I delete the app and relaunch it in simulator for the first time, it runs great; however, when the date changes, meaning the next day of after, the app gives the error below: 2014-06-29 19:48:35.326 App[37398:4803] CoreData: error: (NSFetchedResultsController) The fetched object at index 4 has an out of order section name ' Upcoming. Objects must be sorted by section name' 2014-06-29 19:48:35.328 App[37398:4803] Unresolved error Error

NSSortdescriptor, finding the path to the key I wish to use for sorting

时光怂恿深爱的人放手 提交于 2019-12-06 13:29:03
I am using an NSSortdescriptor to sort a collection of NSArrays, I then came across a case where the particular NSArray to be sorted contains an NSDictionary who contains an NSDictionary. I would like to sort from the string paired with a key in the last dictionary. This is how I would reference the string: NSDictionary *productDict = [MyArray objectAtIndex:index]; NSString *dealerName = [[productDict objectForKey:@"dealer"] objectForKey:@"name"]; How would I use the dealerName in my NSSortdescriptor to sort the array? NSSortDescriptor * sortDesc = [[NSSortDescriptor alloc] initWithKey:/* ? */

Is it possible to have Core Data sort the “many” part of a To-Many relationship during a fetch request?

给你一囗甜甜゛ 提交于 2019-12-06 12:38:41
I'm using Core Data to cache a decent amount of information, and I have a To-Many relationship set up among my managed objects. Naturally I use an NSFetchRequest to fetch an array of the singular side of that relationship. However, I populate a UITableView using the the "many" side of the relationship, and I'd like it to be sorted alphabetically when I pull the data. If I'm not being clear, here's an example: "employee" and "boss" are both NSManagedObjects in a To-Many relationship - each boss has many employees, but employees only have one boss. After retrieving an array of bosses, I push a

How to sort based on a calculated value from multiple Core Data attributes

送分小仙女□ 提交于 2019-12-06 10:16:15
I'm trying to create a sort descriptor, for a core data fetch request, that will fetch objects that are ordered by a calculated value (e.g., the sum of two or more attributes). Is this possible? Thanks in advance. From the "Core Data Programming Guide": You cannot fetch using a predicate based on transient properties (although you can use transient properties to filter in memory yourself). ... To summarize, though, if you execute a fetch directly, you should typically not add Objective-C-based predicates or sort descriptors to the fetch request. Instead you should apply these to the results of

Core Data one-to-many sorting

梦想的初衷 提交于 2019-12-06 06:31:48
问题 I have CoreData object "Entity" with @property (nonatomic, retain) NSSet *ImagesSet; Inside ImagesSet are many "ImageEntity" objects. "ImageEntity" have @property (nonatomic, retain) NSNumber * sortKey; How create fetchRequest for "Entity" with imagesSet ordered by sortKey field? NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"Entity" inManagedObjectContext:[[DataManager sharedInstance] mainObjectContext]];

Customized sort in NSFetchedResultsController

点点圈 提交于 2019-12-06 05:52:48
问题 After spending hours, I found that it was not possible to do customized sort in NSFetchedResultsController backed by SQLite from following article. NSFetchedResultsController custom sort not getting called However, I couldn't find actual solution for my problem. Here's what I am trying to do. Background: I have a English dictionary database (just a simple list of words - very large) in CoreData. Words are shown in UITableView using NSFetchedResultsController. UITableView has an associated

Very custom order using NSSortDescriptor

我的未来我决定 提交于 2019-12-06 04:56:57
问题 Let's say I have objects with different statuses. Statuses are from 0 to 2. I need to sort them using NSSortDescriptor in this way: 1 2 0 Any suggestions? 回答1: Something like this (untested): descriptor = [[[NSSortDescriptor alloc] initWithKey:@"status" ascending:YES selector:@selector(customStatusCompare:)] autorelease]; @interface NSNumber (CustomStatusCompare) - (NSComparisonResult)customStatusCompare:(NSNumber*)other; @end @implementation NSNumber (CustomStatusCompare) -

Using NSSortDescriptor to keep 'nil' values at the bottom of a list

点点圈 提交于 2019-12-06 03:34:49
I'm working on sorting NSFetchedResultController data. I need to sort data by their first name. However, there are some entries with no first name. I need the "no first name" objects to appear the bottom of the list, rather than the top. With the current code, when I sort the list by first name, the "no first name" cells are placed at the top. NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Contacts"]; request.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"firstName" ascending:YES]]; _FRC = [[NSFetchedResultsController alloc] initWithFetchRequest:request

Sort NSArray with custom objects

这一生的挚爱 提交于 2019-12-05 20:31:29
问题 In my Xcode project I have the following classes: Address @interface LDAddress : NSObject{ NSString *street; NSString *zip; NSString *city; float latitude; float longitude; } @property (nonatomic, retain) NSString *street; @property (nonatomic, retain) NSString *zip; @property (nonatomic, retain) NSString *city; @property (readwrite, assign, nonatomic) float latitude; @property (readwrite, assign, nonatomic) float longitude; @end Location @interface LDLocation : NSObject{ int locationId;

How to establish secondary NSSortDescriptor sort key?

自作多情 提交于 2019-12-05 16:33:40
问题 I have successfully sorted the data I have by my sort key lastName , but I want to know how to sort by lastName , and then by firstName . Here is the code I used to sort by lastName NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"firstName" ascending:YES]; [request setSortDescriptors:[NSArray arrayWithObject:sortDescriptor]]; How do I add the secondary sort key of firstName ? 回答1: NSSortDescriptor *sortDescriptor1 = [[NSSortDescriptor alloc] initWithKey:@"firstName"