March 2014 update
This commit is contained in:
parent
09687c4926
commit
a25938f123
1846 changed files with 21876 additions and 5203 deletions
|
|
@ -4,25 +4,25 @@
|
|||
|
||||
int main()
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
@autoreleasepool {
|
||||
|
||||
NSMutableArray *arr =
|
||||
[NSMutableArray
|
||||
arrayWithArray: [@"this is a set of strings to sort"
|
||||
componentsSeparatedByString: @" "]
|
||||
];
|
||||
NSMutableArray *arr =
|
||||
[NSMutableArray
|
||||
arrayWithArray: [@"this is a set of strings to sort"
|
||||
componentsSeparatedByString: @" "]
|
||||
];
|
||||
|
||||
[arr sortUsingComparator: ^NSComparisonResult(id obj1, id obj2){
|
||||
NSComparisonResult l = esign((int)([obj1 length] - [obj2 length]));
|
||||
return l ? -l // reverse the ordering
|
||||
: [obj1 caseInsensitiveCompare: obj2];
|
||||
}];
|
||||
[arr sortUsingComparator: ^NSComparisonResult(id obj1, id obj2){
|
||||
NSComparisonResult l = esign((int)([obj1 length] - [obj2 length]));
|
||||
return l ? -l // reverse the ordering
|
||||
: [obj1 caseInsensitiveCompare: obj2];
|
||||
}];
|
||||
|
||||
for( NSString *str in arr )
|
||||
{
|
||||
NSLog(@"%@", str);
|
||||
}
|
||||
|
||||
for( NSString *str in arr )
|
||||
{
|
||||
NSLog(@"%@", str);
|
||||
}
|
||||
|
||||
[pool release];
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,23 +16,21 @@
|
|||
|
||||
int main()
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
@autoreleasepool {
|
||||
|
||||
NSMutableArray *arr =
|
||||
[NSMutableArray
|
||||
arrayWithArray: [@"this is a set of strings to sort"
|
||||
componentsSeparatedByString: @" "]
|
||||
];
|
||||
NSMutableArray *arr =
|
||||
[NSMutableArray
|
||||
arrayWithArray: [@"this is a set of strings to sort"
|
||||
componentsSeparatedByString: @" "]
|
||||
];
|
||||
|
||||
[arr sortUsingSelector: @selector(my_compare:)];
|
||||
[arr sortUsingSelector: @selector(my_compare:)];
|
||||
|
||||
for ( NSString *str in arr )
|
||||
{
|
||||
NSLog(@"%@", str);
|
||||
}
|
||||
|
||||
NSEnumerator *iter = [arr objectEnumerator];
|
||||
NSString *str;
|
||||
while( (str = [iter nextObject]) != nil )
|
||||
{
|
||||
NSLog(@"%@", str);
|
||||
}
|
||||
|
||||
[pool release];
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,21 +2,17 @@
|
|||
|
||||
int main()
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
@autoreleasepool {
|
||||
|
||||
NSArray *strings = [@"Here are some sample strings to be sorted" componentsSeparatedByString:@" "];
|
||||
NSArray *strings = [@"Here are some sample strings to be sorted" componentsSeparatedByString:@" "];
|
||||
|
||||
NSSortDescriptor *sd1 = [[NSSortDescriptor alloc] initWithKey:@"length" ascending:NO];
|
||||
NSSortDescriptor *sd2 = [[NSSortDescriptor alloc] initWithKey:@"lowercaseString" ascending:YES];
|
||||
NSSortDescriptor *sd1 = [[NSSortDescriptor alloc] initWithKey:@"length" ascending:NO];
|
||||
NSSortDescriptor *sd2 = [[NSSortDescriptor alloc] initWithKey:@"lowercaseString" ascending:YES];
|
||||
|
||||
NSArray *sortDescriptors = [NSArray arrayWithObjects:sd1, sd2, nil];
|
||||
[sd1 release];
|
||||
[sd2 release];
|
||||
NSArray *sorted = [strings sortedArrayUsingDescriptors:@[sd1, sd2]];
|
||||
NSLog(@"%@", sorted);
|
||||
|
||||
NSArray *sorted = [strings sortedArrayUsingDescriptors:sortDescriptors];
|
||||
NSLog(@"%@", sorted);
|
||||
|
||||
[pool release];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue