日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

IOS学习笔记二十NSSet和NSMutableSet

發布時間:2023/12/4 编程问答 86 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。