//集合初始化 NSArray *array = [NSArray arrayWithObjects:@"aa", @"bb", @"cc", nil]; NSSet *se = [NSSet setWithArray:array]; NSLog(@"%@", se); //集合里面只有一个元素 NSSet *set = [NSSet setWithObject:@"aa"]; //只能放一个 NSLog(@"%@", set); NSSet *set1 = [NSSet setWithObjects:@"11",@"66",@"33",@"44",@"55",@"aa", nil]; //如果集合李有重复的会自动合并 NSLog(@"%@", set1); //集合里面是否包含另一个集合Returns a Boolean value that indicates whether every object in the receiving set is also present in another given set. //返回一个布尔值,表示接收组中的每一个对象是否还存在于另一个给定。 BOOL b = [set isSubsetOfSet:set1]; NSLog(@"/////******//////%d",b); //返回一个任意元素,The object returned is chosen at the set’s convenience—the selection is not guaranteed to be random. //返回的对象选择的设置convenience-the选择不能保证是随机的。 NSString *set2 = [set1 anyObject]; NSLog(@"%@", set2); //返回所有的元素,存放在一个书组中, NSArray *all = [set1 allObjects]; //调用所有的object NSLog(@"0.0%@", all); //计算集合长度,个数 NSLog(@"%ld", [set1 count]); //计算集合长度 //判断集合中是否包含某个对象 BOOL a = [set1 containsObject:@"11"]; //判断集合中是否包含某个对象 NSLog(@"%d", a); //Returns an initialized mutable set with a given initial capacity. NSMutableSet *muset = [NSMutableSet setWithCapacity:5]; //向里面存入元素 NSArray *arr = [NSArray arrayWithObjects:@"22", @"33",@"11", nil]; [muset addObjectsFromArray:arr]; NSLog(@"muset == %@", muset); //移除元素 [muset removeObject:@"22"]; NSLog(@"%@", muset); //可变集合 NSCountedSet *count = [NSCountedSet setWithObjects:@"22", @"33", @"33", @"66", nil]; NSInteger coun = [count countForObject:@"33"]; //计算集合中重复元素的个数 NSLog(@"%ld", coun); //集合类型快速枚举 //书组中forin的快速遍历 NSArray *aaa = [NSArray arrayWithObjects:@"11", @"33", @"55", @"99", nil]; for (int i = 0; i < [aaa count]; i++) { NSLog(@"aaa == %@", [aaa objectAtIndex:i]); } for (NSString *i in aaa) { NSLog(@"forin == %@", i); } //字典中forin的快速遍历 NSArray *aaaa = [NSArray arrayWithObjects:@"11", @"22", @"33", @"44", nil]; NSArray *bbbb = [NSArray arrayWithObjects:@"aa", @"bb", @"cc", @"dd", nil]; NSMutableDictionary *cla = [NSMutableDictionary dictionaryWithObjects:bbbb forKeys:aaaa]; NSLog(@"%@", cla); for (NSString *key in [cla allKeys]) { //forin前面的类型就是你要查询的 类型 ,,,切记 。 NSLog(@"value == %@", [cla objectForKey:key]); }
集合
数学中有集合读概念
比如:整数集,自然数集
在比如:集合{1,2,5,}
集合特点
存储的元素互不相同
存储元素是无序的
存储元素必须是对象类型
容器有三个:NSArrey NSdictionary NSSet
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。