March 2014 update

This commit is contained in:
Ingy döt Net 2014-04-02 16:56:35 +00:00
parent 09687c4926
commit a25938f123
1846 changed files with 21876 additions and 5203 deletions

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}