标签:
1、NSSet的使用
NSSet *set = [NSSet setWithObjects:@"25",@"age",@"张三",@"name",@"男",nil]; NSSet *set1 = [NSSet setWithObjects:@"25",@"age",@"张三",@"name",@"男",@"性别",nil]; NSLog(@"set count:%lu", [set count]); //判断是否含有age字符串 if([set containsObject:@"age"]) { NSLog(@"set包含age"); } //判断set 是否等于set1 if ([set isEqualToSet:set1]) { NSLog(@"set 等于 set1"); } //判断set是否是否是set1的子集合 if ([set isSubsetOfSet:set1]) { NSLog(@"set isSubsetOfSet set1"); } //获取所有set对象 NSArray *array = [set allObjects]; NSLog(@"array:%@", array); //迭代遍历 NSEnumerator *enumerator = [set objectEnumerator]; for (NSObject *object in enumerator) { NSLog(@"set1里的对象:%@", object); }
2、NSMutableSet的使用
NSMutableSet继承NSSet,它可以使用NSSet的方法。
NSMutableSet *muSet = [NSMutableSet setWithCapacity:6]; [muSet addObject:@"对象1"]; NSSet *set = [NSSet setWithObjects:@"对象2",@"对象3", @"被企鹅咬了一口", nil]; //添加set数据 [muSet unionSet:set]; for (NSObject *object in muSet) { NSLog(@"all nuSet:%@",object); } NSSet *set1 = [NSSet setWithObjects:@"对象2",@"对象3", nil]; //在muSet中删除包含set1总数据 [muSet minusSet:set1]; for (NSObject *object in muSet) { NSLog(@"after minusSet:%@",object);
标签:
原文地址:http://www.cnblogs.com/sixindev/p/4469151.html