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];
04-10
527
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交