nssortdescriptor

How to sort Core Data array based on Date Entered

做~自己de王妃 提交于 2021-01-13 09:19:18
问题 I have a small Core Data Model which stores an array of Strings (search history). When fetching the Data I'd like to sort by the time created. I currently just have one property in my model called searchHistory is there a way I can use the following code (key: to sort the data or will I need to add a time saved to the model? let request = NSFetchRequest<NSFetchRequestResult>(entityName: entityName) request.sortDescriptors = [NSSortDescriptor.init(key: "", ascending: true)] 回答1: Yes, you need

How to sort Core Data array based on Date Entered

允我心安 提交于 2021-01-13 09:18:08
问题 I have a small Core Data Model which stores an array of Strings (search history). When fetching the Data I'd like to sort by the time created. I currently just have one property in my model called searchHistory is there a way I can use the following code (key: to sort the data or will I need to add a time saved to the model? let request = NSFetchRequest<NSFetchRequestResult>(entityName: entityName) request.sortDescriptors = [NSSortDescriptor.init(key: "", ascending: true)] 回答1: Yes, you need

Does Nssortdescriptor convert contents of the array to integer after sorting?

情到浓时终转凉″ 提交于 2020-01-16 09:08:36
问题 Given the below code, in the first iteration the logs are displayed normally. For the second iteration the app crashes with the following error message: 019-11-07 09:54:08.156277+0100 xxxion[520:202084] iconNumberString : 1026 2019-11-07 09:54:12.160849+0100 xxxtion[520:202084] [self.iconNumbers lastObject]) : 1026 2019-11-07 09:54:24.598805+0100 xxxion[520:202084] -[__NSSingleObjectArrayI addObject:]: unrecognized selector sent to instance 0x2824a3fd0 (lldb) The nssortdescriptor used:

Complex sorting for core-data fetch request

天涯浪子 提交于 2020-01-04 02:35:07
问题 I have an NSEntity ( Cloth ) with an attribute ( type ) which is filled from a list of predefined NSString values i.e. Poncho‎, Jacket, Coat, Gown, Top, Suit, etc. I want to fetch all the Cloth records such that the records are ordered based on a defined order for type . i.e. All the records for Poncho‎ are on top, then Jacket, then Coat, then Gown, then Top, then Suit, etc. Poncho‎ … Poncho‎ … Poncho‎ … Jacket … Jacket … Coat … Coat … Coat … Gown … Gown … Top … Top … Top … Top … Suit … Suit

NSSortDescriptor to-many relationships

大兔子大兔子 提交于 2020-01-03 04:36:08
问题 I use Core Data database. I have Entity Album, that has many entities SpecificImage (key to get set of these images is @"specificImages") I want to get Album with id = 1 and to sort attached SpecificImages by id. I tried NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"specificImages.id" ascending:YES]; but I get the error Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'to-many key not allowed here' Here is my code: NSString

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

家住魔仙堡 提交于 2020-01-02 08:07:39
问题 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:

unsupported NSSortDescriptor (comparator blocks are not supported)

淺唱寂寞╮ 提交于 2020-01-02 01:21:06
问题 In fetchedResultsController while setting the NSSortDescriptor iam getting this error unsupported NSSortDescriptor (comparator blocks are not supported) . NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"Alarm" inManagedObjectContext: managedObjectContext]; [fetchRequest setEntity:entity]; //Below code is not working and causing error. sorting use the hours&seconds part of the time attribute NSSortDescriptor *sort

Sorting NSMutableArray using SortDescriptor AND Predicate possible?

偶尔善良 提交于 2019-12-30 03:27:08
问题 I have an array of type "Restaurant" which has an NSSet of "Rating." Rating has an ID and a value. I want to sort the array of Restaurant's by rating with an ID of 01, from high to low. Something like the following, but how do I use the predicate and sort descriptor together on originalArray? NSPredicate *predicate = [NSPredicate predicateWithFormat:@"Rating.rating_id=%d", ratingID]; NSSortDescriptor *descriptor = [NSSortDescriptor sortDescriptorWithKey:@"currentValue" ascending:YES]; NSArray

NSSortDiscriptor sort positive values

南笙酒味 提交于 2019-12-25 12:41:50
问题 In my core data, I'm asking for x amount of objects sorting by distance (NSNumber[double]) in ascending order. The problem is it gives me back also negative numbers. I know it make sense but I want only positive numbers, how can I do it? NSManagedObjectContext *context = generateManagedObjectContext(); NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:kCORE_DATA_ALL_TRAPS_ENTITY inManagedObjectContext:context];

Baffled by NSMutableArray sortUsingDescriptors: exception

时光怂恿深爱的人放手 提交于 2019-12-25 07:25:09
问题 The following method: - (NSMutableArray*) timeSortedBegins { NSMutableArray* begins = [self.spans valueForKey: @"begin"]; NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey: @"cycleOffsetObject" ascending: YES]; [begins sortUsingDescriptors: @[sort]]; return begins; } throws this runtime exception: 2014-03-21 14:41:32.482 myValve[1741:60b] -[__NSArrayI sortUsingDescriptors:]: unrecognized selector sent to instance 0x16d7bc20 2014-03-21 14:41:32.484 myValve[1741:60b] ***