nssortdescriptor

Sort array that contain alphanumeric words in iOS [duplicate]

对着背影说爱祢 提交于 2019-12-01 15:36:49
问题 This question already has answers here : How to add these object with name to the array by this order? (4 answers) Closed 5 years ago . I have a array with 10 elements called products which is sorted by default, this is the current log now. for (int i=0;i<products.count; i++) { NSLog(@"%@",products[i]); } The Output: Product1 Product10 Product2 Product3 Product4 Product5 Product6 Product7 Product8 Product9 I need to sort it in following order: Product1 Product2 Product3 Product4 Product5

objective-C, sort an array of strings containing numbers [duplicate]

故事扮演 提交于 2019-12-01 14:31:21
问题 This question already has answers here : How to do a natural sort on an NSArray? (5 answers) Closed 5 years ago . Lets suppose I have an array like this NSArray* arr = @[@"1",@"4",@"2",@"8",@"11",@"10",@"14",@"9"]; //note: strings containing numbers and I want to sort them like this: [1,2,4,8,9,10,11,14] but if I use [arr sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)]; I get [1,10,11,14,2,4,8,9]... and if I use: NSSortDescriptor *sortDescriptor = [[NSSortDescriptor

Sort the contents of an NSScrollView, NSTableView, using Binding in ArrayController

旧时模样 提交于 2019-12-01 13:01:59
问题 I have an NSScrollView wich is bound with an ArrayController . I need to sort the content alphabetically. I've tried to do this with bindings but I can't find the right thing to bind. I used the following sortDescriptor on my ArrayController . [myArrayController setSortDescriptors:[NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"myKey" ascending:YES selector:@selector(compare:)]]]; Do I miss a step in the process or am I not even close to sorting the content? 回答1: Did you

NSSortDescriptor with arbitrary sorting

ぐ巨炮叔叔 提交于 2019-12-01 06:36:43
I can't wrap my head around how to do arbitrary sorting with a NSSortDescriptor. I want to do something like this: NSArray *sortAlgorithm = [NSArray arrayWithObjects:@"@", @"#", @"!", @"&", @"r", @"a", nil]; NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES comparator: ^(id obj1, id obj2) { NSComparisonResult comparisonResult; //Some code that uses sortAlgorithm. return comparisonResult; } ]; This would sort the objects by the key name so that any key that starts with @ , e.g. @home , would come before any key that starts with r , e.g. radical , and

NSSortDescriptor - Sort descriptor based on another array

只谈情不闲聊 提交于 2019-12-01 06:28:22
I hava a core data application. And I want to fetch one kind of object, User . User have the property userId . I have another array with userId s, [1, 4, 3, 5] . And I would like to create a NSSortDescriptor that sorts my User objects based on the order of the userId s in the array. Is that possible, and how should I do that? Update I have now tried the following. I added a transformable property to my User object, where I store the user ids array. I have tried the following sort descriptor: sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"userId" ascending:YES comparator:

NSSortDescriptor on transient attribute for NSFetchedResultsController

强颜欢笑 提交于 2019-12-01 03:54:28
Ok, I initially wanted to make NSSortDescriptor of a request for NSFetchedResultsController to sort based on the property in my NSManagedObject subclass, but It obviously won't do it, because NSFetchedResultsController is limited to predicates and sort descriptors that work on the fetched entity and its relations, so I decided to create a transient attribute in my data model, synthesis the property for this attribute to ivar in my NSManagedObject subclass, and sort based on it. When running it, i got while executing fetch 'NSInvalidArgumentException', reason: 'keypath isActive not found in

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

拥有回忆 提交于 2019-11-30 11:21:36
问题 Does anyone know how to fetch some results sorting them alphabetically but ignoring case? 回答1: 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

Sorting NSMutableArray using SortDescriptor AND Predicate possible?

こ雲淡風輕ζ 提交于 2019-11-30 10:01:57
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 *sorted = [[originalArray allObjects] sortedArrayUsingDescriptors:[NSArray arrayWithObject:descriptor]

Core Data Table View Section Sort by weekdays using NSSortDescriptor

╄→гoц情女王★ 提交于 2019-11-30 07:02:25
问题 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

How to sort NSMutableArray of date objects

烂漫一生 提交于 2019-11-30 05:51:27
问题 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.. 回答1: First you should convert all date Strings (which is NSString ) objects to NSDate objects and then sort these dateObjects . I believe you have