Reputation: 67
I have some data like this :
1, 5, 2, 9, 7, 6, 3, 8, 0, 4
but I actually want this:
5, 6, 7, 8, 9
only start to 5 .
and I use this:
NSArray *ary = @[ @"1", @"5", @"2", @"9", @"7", @"6", @"3", @"8", @"0", @"4" ];
NSArray *myArray = [ary sortedArrayUsingDescriptors:
@[[NSSortDescriptor sortDescriptorWithKey:@"doubleValue" ascending:YES]]];
Upvotes: 0
Views: 60
Reputation: 7552
This solution treats the contents as numeric, as suggested by the question's sample code.
double startingValue = 5;
NSArray *ary = @[ @"1", @"5", @"2", @"9", @"7", @"6", @"3", @"8", @"0", @"4" ];
NSArray *myArray= [ary filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self.doubleValue >= %@", @(startingValue)]];
myArray = [myArray sortedArrayUsingDescriptors:
@[[NSSortDescriptor sortDescriptorWithKey:@"doubleValue" ascending:YES]]];
Upvotes: 0
Reputation: 2251
NSString *numberExpr =@"^[5-9]";
NSArray *ary = @[ @"1", @"5", @"2", @"9", @"7", @"6", @"3", @"8", @"0", @"4" ];
NSArray *myArray= [ary filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self MATCHES %@",numberExpr]];
Upvotes: 1