nssortdescriptor

Sorting Number using NSSortDescriptor

◇◆丶佛笑我妖孽 提交于 2019-12-05 10:58:41
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 compares only the 1st digit of every number, mean if there are 2 numbers like 123 and 321 , it will compare 1

Sorting core data position changes with sort descriptors for iPhone

限于喜欢 提交于 2019-12-05 10:24:28
I have a CoreData entity with two attributes. One called 'position' the other called 'positionChange'. Both of them are integers where the position attribute is the current position and the positionChange is the difference between the previous position and the new position. This means that the positionChange can be negative. Now I would like to sort by positionChange. But I would like it to disregard the negative values. Currently I'm sorting it descending, which will give the result: 2, 1, 0, -1, -2. But what I'm looking for is to get this result: 2, -2, 1, -1, 0. Any ideas on how to solve

NSFetchRequest without sort descriptors

谁说胖子不能爱 提交于 2019-12-05 08:02:30
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). 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 care about the date something was created, you should add a dateCreated attribute to your data object. Then,

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

♀尐吖头ヾ 提交于 2019-12-05 07:40:45
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 ObjectB into ObjectA. This would be OK if there really is no way to do this with one fetch request. The

iPhone contacts app styled indexed table view implementation

青春壹個敷衍的年華 提交于 2019-12-04 14:51:43
问题 My Requirement: I have this straight forward requirement of listing names of people in alphabetical order in a Indexed table view with index titles being the starting letter of alphabets (additionally a search icon at the top and # to display misc values which start with a number and other special characters). What I have done so far: 1. I am using core data for storage and "last_name" is modelled as a String property in the Contacts entity 2.I am using a NSFetchedResultsController to display

Core Data one-to-many sorting

限于喜欢 提交于 2019-12-04 13:41:42
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]]; [fetchRequest setEntity:entity]; NSString * predicate = some predicate string......; [fetchRequest

Sorting Array Using NSSortDescriptor [duplicate]

♀尐吖头ヾ 提交于 2019-12-04 13:10:57
问题 This question already has answers here : How to sort NSMutableArray of date objects (3 answers) Closed 6 years ago . I have an array of class A objects, let it be detailsArray. Class A has date, name as properties. Can any one suggest a good method to sort this array based on date? How can I use NSSortDescriptor to sort this array? I know sorting array of dictionary using NSSortDescriptor ... Any help is greatly appreciated..... 回答1: NSSortDescriptor *sortDescriptor = [NSSortDescriptor

Very custom order using NSSortDescriptor

╄→尐↘猪︶ㄣ 提交于 2019-12-04 12:56:34
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? 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) - (NSComparisonResult)customStatusCompare:(NSNumber*)other { NSAssert([other isKindOfClass:[NSNumber class]], @"Must be a

Customized sort in NSFetchedResultsController

穿精又带淫゛_ 提交于 2019-12-04 09:37:03
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 Search Bar. When an user inputs a string in Search Bar, UITableView shows a list of words filtered. Why do

NSSortDescriptor: Custom comparison on multiple keys simultaneously

不打扰是莪最后的温柔 提交于 2019-12-04 07:06:39
I have an custom object which contains time period based information, for instance the attributes endCalYear, endMonth and periodLength which indicate the end of each period and its length. I would like to create an NSSortDescriptor based or other sorting method which combines these three attributes and allows sorting this object on all three keys at the same time. Example: EndCalYear endMonth periodLength (months) sortOrder 2012 6 6 1 2012 6 3 2 2012 3 3 3 2011 12 12 4 The sort algorithm would be completely discretionary based on my own algorithm. How could I code such an algorithm? The block