您好,登錄后才能下訂單哦!
//集合初始化 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(@"http://///******//////%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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。