nssortdescriptor

Sorting with sortedArrayUsingDescriptors and Key Paths

牧云@^-^@ 提交于 2019-12-17 20:06:09
问题 I have an unordered array with instances of the following class: @interface Place : NSObject { } @property (nonatomic, copy) NSString *country; @property (nonatomic, copy) NSString *city; @property (nonatomic, retain) NSURL *imageURL; -(id) initWithCountry: (NSString *) aCountry city: (NSString *) aCity imageUrl: (NSURL *) aUrl; @end and I'm trying to sort it with sortedArrayUsingDescriptors by country and city. The docs for NSSortDescriptor say that the arg of initWithKey: is a Key Path.

Sort UITableView by distance

拈花ヽ惹草 提交于 2019-12-13 15:16:36
问题 I am trying to sort my tableview in ascending order by distance that I calculate from coordinates. Everything works like a charm except I can't get it in ascending order, I have been mucking around with NSSortDescriptor etc., but getting unlucky, any help would be appreciated, here is my code: - (void) retrieveData { NSURL *url = [NSURL URLWithString:jsonFile]; NSData *data = [NSData dataWithContentsOfURL:url]; _jsonArray = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions

How to sort an array in descending order in iPhone [duplicate]

我与影子孤独终老i 提交于 2019-12-13 10:39:18
问题 This question already has answers here : How do I sort an NSMutableArray with custom objects in it? (25 answers) Sorting an NSArray in reverse order (2 answers) Closed 5 years ago . I am trying to sort an array in descending order,I can sort array in ascending order,Here is my code to sort in ascending order, NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"year" ascending:NO]; NSArray * descriptors = [NSArray arrayWithObjects:sortDescriptor, nil]; sortedArray =

How to sort month name in ascending or descending order using NSSortDescriptor in objective c

邮差的信 提交于 2019-12-13 08:29:41
问题 i need to sort the month and year in ascending or descending order using NSSortDescriptor i have one array { month = Dec; year = 2017; }, { month = Oct; year = 2017; }, { month = Jan; year = 2018; } i used to done this code NSSortDescriptor * sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"year" ascending:YES]; NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor]; yeardata = [NSMutableArray arrayWithArray:[yeardata sortedArrayUsingDescriptors:sortDescriptors]]; for

Using NSSortDescriptor to sort build numbers with Core Data

回眸只為那壹抹淺笑 提交于 2019-12-12 17:29:59
问题 I'm trying to use NSSortDescriptor with Core Data to sort build numbers/software versions (NSStrings). The build numbers are actually just NSStrings but it seems to have a hard time with this. I'm guessing because of the multiple and irregular decimal points. For example, I would like to sort the following. 1.7.6 1.8 1.6.2 1.9.0.1 2.0 Each line represents an NSString . How would I do this properly or is there another way I should try? 回答1: A sort descriptor using localizedStandardCompare:

Custom NSSortDescriptor on complex object

眉间皱痕 提交于 2019-12-12 16:24:54
问题 It's my first post so sorry if I may not respect all the conventions even though I'll try my best. I have always found solutions to my problems on SO before but I'm completely stuck on a rather complex Cocoa problem. I am trying to achieve a complex sort on a list of CoreData objects. I have a catalog composed of Book objects, which can be part of Saga (first book and its sequels). The simplified structures look like this: @interface Book : NSManagedObject @property (nonatomic, retain)

NSSortDescriptor sorting using NSDate in Swift

大城市里の小女人 提交于 2019-12-12 09:30:20
问题 How would I sort a NSFetchRequest with that the date property of the managed object. So that it creates a array with the dates going in order? Here is my code so far... var request : NSFetchRequest = NSFetchRequest(entityName: "History"); request.predicate = NSPredicate(format: "counts = %@", true) request.sortDescriptors = [???] <- What should I put here? var results : [NSManagedObject] = context.executeFetchRequest(request, error: nil) as [NSManagedObject] 回答1: // newest first request

How should I fix this code?

百般思念 提交于 2019-12-12 05:36:59
问题 I'm trying to sort an array of people objects. The class looks like this. Person ------- name phone I have an NSMutableArray filled with these objects. I want to sort this array by the name of each person object. This is the code I tried. NSSortDescriptor *desc = [[NSSortDescriptor alloc] initWithKey: @"name" ascending: YES]; [personArray sortedArrayUsingDescriptors: [NSMutableArray arrayWithObject: desc]]; It doesn't work. How can it be changed to work? 回答1: You're aware that

Sort Descriptor Not functioning correctly or consistently

女生的网名这么多〃 提交于 2019-12-12 02:49:05
问题 I am using a sort descriptor and a set predicate between 4 entities. entity one: workoutType Relationship workouts 1 to many entity two: workoutSet Relationship days 1 to many entity three: workoutDay relationship exercises 1 to many entity four: workoutExercise Inverses are also set. The problem i am receiving is that the sortDescriptor is working correctly behind the scenes, but what is displayed is incorrect. For example in my workoutDay entity i have attribute dayName of string type.

iPhone: How to Sort Dates Using NSDate?

你离开我真会死。 提交于 2019-12-12 01:45:56
问题 I have to sort objects based on NSDates. What are the options for sorting by NSDate? 回答1: In general you use a NSSortDescriptor to define the sort of collections like arrays or Core Data. You call the sort from the collection object itself. NSDate itself has comparison functions if you want to do the sort directly yourself. 回答2: You can do sorting of date by comparing two dates.For that you should use. NSComparisonResult class. NSComparisonResult result=[date1 compare:date2]; if result=