_____________________________不可變集合NSSet_________________________________________
數(shù)組 NS(Mutable)Array 有序 (...)
字典 NS(Mutable)Dictionary 無(wú)序 鍵值對(duì) {key = value}
集合 NS(Mutable)Set 無(wú)序 {(...)}
//1.創(chuàng)建
//空集合
NSSet *set = [[NSSet alloc]init];
NSSet *set1 = [NSSet set];
//by數(shù)組
NSSet *set2 = [[NSSet alloc]initWithArray:@[@1,@2]];
//by元素
NSSet *set3 = [[NSSet alloc]initWithObjects:@1,@2,nil];
//by集合
NSSet *set4 = [[NSSet alloc]initWithSet:set3];
//2.屬性
NSLog(@"%ld",set4.count);
//3.方法
/*
集合中獲取對(duì)象:1.含有多個(gè)對(duì)象的集合沒(méi)有下標(biāo),也沒(méi)有key,所以獲取的結(jié)果不能夠預(yù)知
*/
//獲取一個(gè)對(duì)象
NSNumber *number = [set4 anyObject];
//不知道對(duì)象類型的時(shí)候可以使用id
id objc = [set4 anyObject];
NSLog(@"%@',number);
//判斷是否含有某個(gè)對(duì)象
BOOL isTrue = [set4 containsObject:@1];
/*___________________________可變集合 NSMutableSet_____________________________________________*/
NSMutableSet *set5 = [[NSMutableSet alloc]init];
NSMutableSet *set6 = [NSMutableSet set];
//1.添加對(duì)象
[set6 addObject:@3];
[set6 addObjectsFromArray:@[@2,@1]];
//2.移除對(duì)象
[set removuObject:@3];
//[set6 removeAllObjects];
//3.
/*
控制臺(tái)輸出集合 -> {(集合內(nèi)容/...)}
NSLog()
*/