nssortdescriptor

Custom sorting with NSFetchedResultController (subclassing NSSortDescriptor)

最后都变了- 提交于 2019-11-30 05:15:09
问题 I want to provide custom sorting using NSFetchedResultsController and NSSortDescriptor. As custom sorting via NSSortDescriptor message -(id)initWithKey:ascending:selector: is not possible (see here), I tried to use a NSSortDescriptor derived class in order to override the compareObject:toObject: message. My problem is that the compareObject:toObject: is not always called. It seems that it is called only when the data are already in memory. There is an optimization of some sort that use a

iPhone CoreData - How to fetch managed objects, and sorting them ignoring case?

北战南征 提交于 2019-11-29 23:52:46
Does anyone know how to fetch some results sorting them alphabetically but ignoring case? vfn Thank you for your reply, but I need to sort the result of a simple "query" ignoring case. Your suggestion applies for searching and comparing. SQL speaking, I need an ORDER BY firstName ASC , and this command must be case insensitive for my usage. I have done some Googling and I ended reading the NSSortDescriptor Class reference , and I could find the answer for my question. The solution is setting a selector to the sort descriptor as follow: NSSortDescriptor *sortDescriptor = [[NSSortDescriptor

Locations in Core Data sorted by distance via NSFetchedResultsController?

浪尽此生 提交于 2019-11-29 06:55: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 ideal scenario, I'm able to refresh that list to recalculate the sort based on a new location. Therefore

How to sort array controller alphabetically with numbers last in objective-c?

橙三吉。 提交于 2019-11-29 05:06:17
I have an NSArrayController and I would like to sort the contents so that anything with English alphabets are sorted first and then anything with numbers and non English characters are sorted last. For example: A, B , C ... Z, 1 , 2, 3 ... 9, 구, 결, ... Currently I only know how to sort items in alphabetical order. Suggestions? NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES]; [dataController setSortDescriptors: [NSArray arrayWithObject: sort]]; You can use sortedArrayUsingComparator to customize the sort algorithm to your needs. For instance, you can give

Core Data Table View Section Sort by weekdays using NSSortDescriptor

邮差的信 提交于 2019-11-29 00:41:29
I'm currently trying to sort my array of objects into day order so they can be grouped in the correct order i.e. Monday, Tuesday, Wednesday then by start time. Only problem is I can't figure out how to do this, my code currently looks like this: Which sorts alphabetically then by time: NSString *sectionKey = nil; switch (tab) { case kByWeekA: { NSSortDescriptor *sortDescriptor1 = [[NSSortDescriptor alloc] initWithKey:@"day" ascending:NO]; NSSortDescriptor *sortDescriptor2 = [[NSSortDescriptor alloc] initWithKey:@"starttime" ascending:YES]; NSArray *sortDescriptors = [[NSArray alloc]

Custom sorting using categories and core data - is it supported by the framework?

血红的双手。 提交于 2019-11-28 04:50:21
问题 I'm developing for iPhone iOS 4.0 and I have a list of birthday objects (date + name) stored using Core Data. I want to use the NSFetchedResultsController to retrieve this list sorted by the next birthdate date of each birthday object. For that I need to define my own logic for the sort descriptor. I tried using: [NSSortDescriptor sortDescriptorWithKey:@"birthdayDate" ascending:YES selector:@selector(compareNextBirthday:)]; Where compareNextBirthday: is defined in a category I created on a

Help sorting an NSArray across two properties (with NSSortDescriptor?)

爷,独闯天下 提交于 2019-11-28 00:23:21
问题 I'm a bit of a NSSortDescriptor n00b. I think, though, it is the right tool for what I need to do: I have an NSArray consisting of objects with keys, say, "name" and "time". Instead of verbalizing it, here's an example: input: name: time B: 4 C: 8 B: 5 C: 4 A: 3 C: 2 A: 1 A: 7 B: 6 desired output: name: time A: 1 <--- A: 3 A: 7 C: 2 <--- C: 4 C: 8 B: 4 <--- B: 5 B: 6 So the values are sorted by "time" and grouped by "name". A comes first because he had the smallest time value, and all values

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

How to sort NSMutableArray of date objects

北城以北 提交于 2019-11-27 21:41:18
I'm doing some small work on sorting the date strings in the NSMutableArray, i'm getting the array from the sqlite db. If you print the array it is showing like this date strings are ( "2011-05-01", "2011-02-01", "2012-01-08", "2012-05-08", "2010-01-09 ) I want to show the dates in ascending order. Please help me out guys..... I'm newbie to objc.. Anoop Vaidya First you should convert all date Strings (which is NSString ) objects to NSDate objects and then sort these dateObjects . I believe you have dateArray containing all those strings. NSSortDescriptor *descriptor = [[NSSortDescriptor alloc

Keypath <transientproperty> not found in entity

不问归期 提交于 2019-11-27 17:52:05
问题 I want to show a formatted date in the section header of a table view.. I used the following code.but its throwing an exception *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'keypath dateSectionIdentifier not found in entity <NSSQLEntity Expense id=1>' . guess the exception is coming when adding a sort descriptor. NSMutableArray *sortDescriptors = [[NSMutableArray alloc] initWithCapacity:20]; NSSortDescriptor *mainSortDescriptor = [[NSSortDescriptor alloc