nssortdescriptor

Sorting Array Based on custom object values

血红的双手。 提交于 2019-12-08 12:57:47
问题 I Need to Sort out an array of custom objects. The object is simple, it stores an x and y co-ordinate, for example: XYPointObject.xCoordinate = [NSNumber]; XYPointObject.yCoordinate = [NSNumber]; I have an array that stores up to 676 of these objects that I need to sort into a numerical order as in x values in numerical order, and the y values connected to the x values in order as well. for example, if the input co-ordinates are: 23,5 | 5,7 | 1,4 | 1,7 | 21,8 | 9,12 | 16,19 the sorted array

NSSortDescriptor and NSPredicate for sorting and filtering

蓝咒 提交于 2019-12-08 09:39:37
问题 I have a tableView that has 5 different possible datasources depending on a flag object (NSNumber *)dataSourceAssignment . I've implemented an NSSortDescriptor that sorts dataSource by a (float)confidenceRating . After the datasource is assigned, I need to be able to filter the dataSource array by a (NSString *)genre . I understand how to use NSPredicate to filter my array, but I can't figure out how to do it efficiently when there are 5-6 different genre strings that could be checked. The

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

两盒软妹~` 提交于 2019-12-08 05:22:55
问题 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.

Writing compare: method in Objective-C

馋奶兔 提交于 2019-12-08 04:50:16
问题 I saw this post: How to sort an NSMutableArray of objects by a member of its class, that is an int or float And had something similar, but I wasn't sure how it all works and was hoping for some guidance. I have an Array of Marker objects that have a Type ivar that takes on values of 0, 1, 2. I want to have a check box that says what to order by, 0, 1, or 2. I started off by trying to doing something similar in my own method: - (NSComparisonResult)Type:(id)otherObject { if ([self Type] >

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

♀尐吖头ヾ 提交于 2019-12-08 00:38:51
问题 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. 回答1: 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

NSSortDescriptor with first name and last name,or with either first name or last name?

余生颓废 提交于 2019-12-07 20:25:19
问题 I am doing sorting of an contact info array,it's working fine when I entered first name and last for particular contact,but it's not working fine when any of it is missing, For Ex: if I enter first name John and last name mickey ,then it gives proper sorting,but if I enter only mickey then it comes at last in # section in UITableview.,so what I need to do here in this type of case. My code is as below, NSSortDescriptor *sortDescriptorFirstName = [[[NSSortDescriptor alloc] initWithKey:@

Sorting Number using NSSortDescriptor

扶醉桌前 提交于 2019-12-07 05:28:23
问题 I got stuck in another problem again but after a long time. This time I have database (Core Data), having an attribute of numbers which contains integer numbers like 213879,123,4,345,56567 and so. I need to fetch data in ascending number order similar to like alphabetically order. I am doing this in way given below, fetchRequest.sortDescriptors=[NSArray arrayWithObject: [NSSortDescriptor sortDescriptorWithKey:@"numbers" ascending:YES selector:@selector(compare:)]]; but unfortunately it

NSFetchRequest without sort descriptors

混江龙づ霸主 提交于 2019-12-07 03:32:29
问题 We cannot use NSFetchRequest without providing NSSortDescriptor(s). All i want to do is fetch the results and show them in the order in which they were created. Is there a built-in way to do that?, or will i have to create a new "auto-increment" field? (which goes against everything CoreData stands for, in my opinion). 回答1: Core Data does not guarantee anything about order. You don't have to make an "auto-increment" field; however, you can make an appropriate attribute. Since you obviously

How to sort Core Data results based on an attribute of related object collection?

岁酱吖の 提交于 2019-12-07 03:07:51
问题 Setup: I have a collection of parent objects, call them ObjectA. Each ObjectA has a one-to-many relation to ObjectB. So, one ObjectA may contain 0..n ObjectB-s, and each ObjectB has a specific ObjectA as its parent. Now, I would like to do a Core Data fetch of ObjectA-s, where they are sorted by their latest ObjectB. Is it possible to create a sort descriptor for that? There is a related question that describes exactly the same situation. The answer suggests denormalizing the attribute from

NSSortDescriptor to sort by number of items in Core Data To-Many Relationships

时间秒杀一切 提交于 2019-12-07 02:04:16
问题 It's a long standing problem when using Core Data to-many-relationships that it is very hard to sort a fetch request using NSSortDescriptor on a Parent entity based on the number of children are in a one-to-many relationship to a Child entity. This is especially useful in combination with a NSFetchedResultsController . Typically initializing the sort descriptor as: NSSortDescriptor *sortByNumberOfChildren = [[NSSortDescriptor alloc] initWithKey:@"children.@count" ascending:NO]; results in an