// // main.m #import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { //不能重复 无序 继承NSSet NSMutableSet *mset = [NSMutableSet setWithCapacity:10]; [mset addObject:@"one"]; [mset addObject:@"two"]; [mset addObject:@"one"]; [mset addObject:@"two"]; NSMutableSet *set1= [NSMutableSet setWithObjects:@"a",@"b",@"c",@"d", @"two",nil]; NSLog(@"%@",mset); // [mset removeObject:@"one"]; NSLog(@"%@",mset); NSLog(@"%ld",mset.count); NSEnumerator *e = [mset objectEnumerator]; NSString *s; while ((s=[e nextObject])!=0) { NSLog(@"%@",s); } NSArray *array = [NSArray arrayWithObjects:@"1",@"2",@"3",@"4", nil]; [mset addObjectsFromArray:array]; NSLog(@"%@",mset); [mset removeAllObjects]; //交集 [mset intersectSet:set1]; NSLog(@"%@",mset); //求两个集合的并集 [mset unionSet:set1]; NSLog(@"111%@",mset); //差集 [mset minusSet:set1]; NSLog(@"111%@",mset); } return 0; }
原文:http://www.cnblogs.com/WJR12/p/5061623.html