_____________________________不可變集合NSSet_________________________________________
數組 NS(Mutable)Array 有序 (...)
字典 NS(Mutable)Dictionary 無序 鍵值對 {key = value}
集合 NS(Mutable)Set 無序 {(...)}
//1.創建
//空集合
NSSet *set = [[NSSet alloc]init];
NSSet *set1 = [NSSet set];
//by數組
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.方法
/*
集合中獲取對象:1.含有多個對象的集合沒有下標,也沒有key,所以獲取的結果不能夠預知
*/
//獲取一個對象
NSNumber *number = [set4 anyObject];
//不知道對象類型的時候可以使用id
id objc = [set4 anyObject];
NSLog(@"%@',number);
//判斷是否含有某個對象
BOOL isTrue = [set4 containsObject:@1];
/*___________________________可變集合 NSMutableSet_____________________________________________*/
NSMutableSet *set5 = [[NSMutableSet alloc]init];
NSMutableSet *set6 = [NSMutableSet set];
//1.添加對象
[set6 addObject:@3];
[set6 addObjectsFromArray:@[@2,@1]];
//2.移除對象
[set removuObject:@3];
//[set6 removeAllObjects];
//3.
/*
控制臺輸出集合 -> {(集合內容/...)}
NSLog()
*/