NSInteger randomize(id num1, id num2, void *context)
{
int rand = arc4random() %2;
if (rand)
return NSOrderedAscending;
else
return NSOrderedDescending;
}
NSMutableArray *temp=[[NSMutableArray alloc] init];
for ( int i=0; i<=10; i++) {
[temp addObject:[NSString stringWithFormat:@"%d",i]];
}
[temp sortUsingFunction:randomize context:NULL];
NSLog(@"%@",temp);
{
int rand = arc4random() %2;
if (rand)
return NSOrderedAscending;
else
return NSOrderedDescending;
}
NSMutableArray *temp=[[NSMutableArray alloc] init];
for ( int i=0; i<=10; i++) {
[temp addObject:[NSString stringWithFormat:@"%d",i]];
}
[temp sortUsingFunction:randomize context:NULL];
NSLog(@"%@",temp);
No comments:
Post a Comment