IOS学习笔记二十NSSet和NSMutableSet
生活随笔
收集整理的這篇文章主要介紹了
IOS学习笔记二十NSSet和NSMutableSet
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1、NSSet、NSMutableSet
NSSet元素無序、不能重復
NSMutableSet元素無序、不能重復,有一些向集合中增加元素的功能、刪除元素.......
?
?
?
?
2、測試Demo
int main(int argc, char * argv[]) {@autoreleasepool {NSSet *set = [NSSet setWithObjects:@"chenyu", @"hello", @"word", @"see", nil];set = [set setByAddingObject:@"chenxuan"];for (id object in set){NSLog(@"%@", object);}NSSet *set1 = [NSSet setWithObjects:@"chenyu1", @"hello1", @"word", @"see", @"see", @"hello1", nil];//set和set1的并集NSLog(@".......");NSSet *s = [set setByAddingObjectsFromSet:set1];for (id object in s){NSLog(@"%@", object);}//是否有交集NSLog(@"set1 和 set 是否有交集:%d", [set1 intersectsSet:set]);//set1是否是set集合的子集BOOL bo = [set1 containsObject:@"see"];NSLog(@"set1 是否包含 see %d", bo);NSLog(@"-------");NSMutableSet *set2 = [NSMutableSet setWithCapacity:10];[set2 addObject:@"chenyu"];[set2 addObject:@"hello"];[set2 addObject:@"hello"];[set2 addObject:@"hello"];[set2 addObject:@"hello1"];[set2 addObject:@"hello3"];NSLog(@"-------");for (id object in set2){NSLog(@"%@", object);}NSLog(@"-------");[set2 removeObject:@"hello1"];for (id object in set2){NSLog(@"%@", object);}} }?
?
?
?
?
?
3、運行結果
2018-07-18 23:26:20.748305+0800 cyTest[33554:12766983] hello 2018-07-18 23:26:20.748415+0800 cyTest[33554:12766983] chenyu1 2018-07-18 23:26:20.748554+0800 cyTest[33554:12766983] word 2018-07-18 23:26:20.749114+0800 cyTest[33554:12766983] set1 和 set 是否有交集:1 2018-07-18 23:26:20.749626+0800 cyTest[33554:12766983] set1 是否包含 see 1 2018-07-18 23:26:20.749838+0800 cyTest[33554:12766983] ------- 2018-07-18 23:26:20.750052+0800 cyTest[33554:12766983] ------- 2018-07-18 23:26:20.773300+0800 cyTest[33554:12766983] chenyu 2018-07-18 23:26:20.789523+0800 cyTest[33554:12766983] hello1 2018-07-18 23:26:20.791472+0800 cyTest[33554:12766983] hello3 2018-07-18 23:26:20.791896+0800 cyTest[33554:12766983] hello 2018-07-18 23:26:20.797038+0800 cyTest[33554:12766983] ------- 2018-07-18 23:26:20.800879+0800 cyTest[33554:12766983] chenyu 2018-07-18 23:26:20.804327+0800 cyTest[33554:12766983] hello3 2018-07-18 23:26:20.804808+0800 cyTest[33554:12766983] hello?
總結
以上是生活随笔為你收集整理的IOS学习笔记二十NSSet和NSMutableSet的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android之运行PopupWindo
- 下一篇: IOS学习笔记二十一(NSDiction