nssortdescriptor

Do Cocoa NSSortDescriptors belong in the model or the controller?

Would NSSortDescriptor subclasses be placed in the Model or the Controller layer? Since they are primarily for display and business logic, it seems to make sense to put them in the Controller layer. But it also makes sense that models should know how to sort themselves. ...

How do you sort NSNumber with NSSortDescriptor?

I'm having trouble sorting an NSNumber using NSSortDescriptor. For whatever reason it won't sort into the correct order. What am I doing wrong? - (NSNumber *)sortNumber { NSNumber *sum = [NSNumber numberWithFloat:([self.capacity floatValue] / [self.availability floatValue])]; return sum; } It is defined as an Int32 in the xcdataMode...

Is it possible to Sort Arrays with custom objects containing String elements localized AND with correct Numbers in Cocoa Touch?

Assumed having the class Account with Name and accountNo both as NSStrings. I want to sort an Array of Accounts either by name or by accountNo. The sort should be done localized. If I use NSSortDescriptors as described in the Guides I have the option to pass localizedCaseInsensitiveCompare: to the Array, but the numbers are not sorted c...

Sorting an Array of custom objects by a dictionary included in the custom object: How?

I have an array of custom objects. The objects includes a dictionary. Something like this: CustomDataModel *dataModel; dataModel.NSString dataModel.NSDictionary dataModel.image I'd like to sort by one of the objects in the dictionary: dataModel.NSDictionary ObjectWithkey=@"Name" The dataModel gets loaded into an NSArray. I now wan...

How to sort model object by object in dictionary?

Hi, I've a model object that extends from NSObject called column. Column has two fields, properties and data. Properties is an NSDictionary that stores arbitrary key/value pairs while data is an array. Columns come in arrays and I need to sort them by a value I know will always be in properties, a value with the key ordinal_position. ...

Core Data Table View Section Sort by weekdays using NSSortDescriptor

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 k...

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

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: ...

iPhone Fetch Request with localized sorting

I'm trying to get sorted localized data from a core data model. My code: NSEntityDescription *entityDescription = [NSEntityDescription entityForName: entityDescriptionValue inManagedObjectContext: context]; NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; [fetchRequest s...

NSSortDescriptor for NSFetchRequestController causes crash when value of sorted attribute is changed

I have an Core Data Entity with a number of attributes, which include amount(float), categoryTotal(float) and category(string) The initial ViewController uses a FethchedResultsController to retrieve the entities, and sorts them based on the category and then the categoryTotal. No problems so far. NSManagedObjectContext *moc = [self ma...

Sorting by date format in iphone

I am new to iphone development.I am sorting a mutable array with respect to date.But it is sorting Using the date parameter consider it as string.I want to sort it by date.How can i achieve that .Please help me out. NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"pubDate" ascending:YES]; [stories sortUsingDescrip...

iPhone: How to Sort Dates Using NSDate ?

I have to sort objects based on NSDates. What are the options for sorting by NSDate? ...

Core Data and NSDate

Hi ! I read this post but I don't really understand the code... I have a core data database with an Entity and some attributes. One of them is named "myDate" and has for type NSDate. Now I want to to display each date but eliminate dates with same day-month-year and display them ascendantly . Have you got an idea? Thanks a lot ! ...

[iPhone] How to order an array

Hi all, I got an array in my app and I need to order by one of its key. Basically what the app does is taking latitude and longitude somewhere, calculate the distance from my actual position and create an array containing a key called "distance". I'm using myArray sortUsingDescriptors: [NSArray arrayWithObject:[[[NSSortDescriptor...

Core Data NSFetchedResultsController sorting in certain sequence

I'm writing iphone app that has UITableView and uses Core Data. Data in UITableView is shown using NSFetchedResultsController. I use NSPredicate operator "IN" to fetch only needed entries. NSArray *filterArray = [NSArray arrayWithObjects:@"789", @"963", @"445", @"198", nil]; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"i...

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

Hi 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 *productDic...

iPhone contacts app styled indexed table view implementation

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...

Which sorting algorithm is behind an NSSortDescriptor?

Is that thing using bubble sort? Or what exactly? How does it work in context with an NSFetchRequest of Core Data? ...

Core Data NSSortDescriptor causing memory leak

I am getting a memory leak when I add a sort descriptor to my Fetch Request in Core Data. If I comment out the NSSortDescriptor block it runs without a memory leak in Instruments. NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"Pools" inManagedObjectConte...

how to sort an NSMutable Array reference to date in iphone

Hello All I need to sort an NSMutable Array that having a class Objects say Item . Item class have date,url,link,title,guid etc .. I am storing this Object Into an NsMutableArray each time. so MyArray will have number Of Item class Objects .. now I need to sort Myarray using date attribute . Can any one tell me the way. Thanks ...

NSFetchRequest without sort descriptors

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). ...