Created
June 7, 2013 15:51
-
-
Save sergiosvieira/5730278 to your computer and use it in GitHub Desktop.
sorting array of keys of nsdictionary based on value of nsdictionary
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSDictionary *original = @{ | |
@"Campo de Teste" : @{@"order" : @"1"}, | |
@"Alguma coisa" : @{@"order" : @"4"}, | |
@"outro teste" : @{@"order" : @"2"}, | |
@"fala cara" : @{@"order" : @"3"}, | |
}; | |
NSArray *sortedArray; | |
sortedArray = [original.allKeys sortedArrayUsingComparator:^NSComparisonResult(NSString *a, NSString *b) { | |
NSDictionary *dfirst = original[a]; | |
NSDictionary *dsecond = original[b]; | |
NSNumberFormatter * f = [[NSNumberFormatter alloc] init]; | |
[f setNumberStyle:NSNumberFormatterDecimalStyle]; | |
NSNumber *first = [f numberFromString:dfirst[@"order"]]; | |
NSNumber *second = [f numberFromString:dsecond[@"order"]]; | |
return [first compare:second]; | |
}]; | |
NSLog(@"%@", sortedArray); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment