//NSSet 集合[特点:(1)存储对象(2)无需性(3)随机取(4)元素不能重复]
// Person * p1 = [[Person alloc] initWithName:@"张山" sex:@"男" age:25];
// Person * p2 = [[Person alloc] initWithName:@"李四" sex:@"男" age:54];
// Person * p3 = [[Person alloc] initWithName:@"杨紫" sex:@"女" age:20];
// Person * p4 = [[Person alloc] initWithName:@"张1山" sex:@"男" age:21];
// Person * p5 = [[Person alloc] initWithName:@"李2四" sex:@"男" age:52];
// Person * p6 = [[Person alloc] initWithName:@"杨3紫" sex:@"女" age:23];
// NSSet * set = [NSSet setWithObjects:p1, p2, p3, p4, p5, p6, nil];
// NSLog(@"set = %@",set);
// Person * getp = [set anyObject];
// NSLog(@"%@",getp);
//
// Person * getp1 = [set anyObject];
// NSLog(@"%@",getp1);
//
// Person * getp2 = [set anyObject];
// NSLog(@"%@",getp2);
// NSArray * array = [NSArray arrayWithObjects:p1, p2, p3, p4, p5, p6, nil];
// for (Person * per in array) {//快速枚举
// NSLog(@"%@",per);
// }
// for (int i = 0; i < [array count]; i++) {
// Person * pr = [array objectAtIndex:i];
// NSLog(@"%@",pr);
// }
// NSArray * stringArray = [NSArray arrayWithObjects:@"zhangsan", @"lisi", @"man", p1, p5, nil];
// for (NSString * s in stringArray) {
// NSLog(@"%@",s);
// }
// for (id obj in stringArray) {//打印不同类型的
// NSLog(@"%@",obj);
// }
// for (id obj in stringArray) {
// if ([obj isKindOfClass:[NSString class]]) {//打印某种类型的
// NSLog(@"%@",obj);
// }
// }
//
// NSDictionary * dic = [NSDictionary dictionaryWithObjectsAndKeys:@"张三",@"name", @"男", @"性别", @"19", @"age", nil];
// for (NSString * key in dic) {
// NSLog(@"key = %@",key);
// NSString * value = [dic objectForKey:key];
// NSLog(@"%@",value);
// }
/*********/ //for in语法里面不允许对可变数组或字典,增删元素
// NSMutableArray * array = [NSMutableArray arrayWithObjects:p1, p2, p3, p4, p5, p6, nil];
// for (Person * per in array) {
// [array removeObject:per];
// }
// NSLog(@"array = %@",array);
// NSArray * stringArray = [NSArray arrayWithObjects:@"zhangsan", @"lisi", @"wangwu", @"zhaoliu", @"hanqi", @"guoba", @"hejiu", @"xiaoshiyi", @"niulang", @"guxi", nil];
// NSArray * newArray = [stringArray sortedArrayUsingSelector:@selector(compare:)];
// // NSLog(@"%@",newArray);
// Person * s = [[Person alloc] initWithName:@"zhangsan" sex:@"man" age:19];
// [s printLog:@selector(test)];
转载于:https://blog.51cto.com/zhangys2007/1605945