直接上代码:
NSLog( @"++++++++++++++++++" ) ;
NSArray *testArray = @[@1, @2, @3, @4, @5] ;
for (NSArray *object in testArray) {
NSLog( @"%@", object ) ;
}
for ( id object in testArray ) {
NSLog( @"%@", object ) ;
}
for ( id object in set1 ) {
NSLog( @"%@", object ) ;
}
for ( id object in dic1 ) {
NSLog( @"%@", object ) ;
}
for ( NSString *key in dic1) {
NSLog( @"dictionary[%@]:%@", key, dic1[key] ) ;
}
NSArray *array1 = @[@1, @2, @5, @3, @4] ;
NSArray *resultArray = [array1 sortedArrayUsingSelector:@selector(compare:)] ;
NSLog( @"%@", resultArray ) ;
Student *stu1 = [Student studentWithName:@"wang" score:@85] ;
Student *stu2 = [Student studentWithName:@"zhen" score:@95] ;
Student *stu3 = [Student studentWithName:@"gang" score:@65] ;
NSMutableArray *stus = [NSMutableArray array] ;
[stus addObject:stu1] ;
[stus addObject:stu2] ;
[stus addObject:stu3] ;
[stus sortedArrayUsingSelector:@selector(scoreAscending:)] ;
NSLog( @"%@", stus ) ;
[stus sortedArrayUsingSelector:@selector(scoreDescending:)] ;
NSLog( @"%@", stus ) ;
[stus sortedArrayUsingSelector:@selector(nameAscending:)] ;
NSLog( @"%@", stus ) ;
[stus sortedArrayUsingSelector:@selector(nameDescending:)] ;
NSLog( @"%@", stus ) ;