main.m
#import <Foundation/Foundation.h> @interface NSSet(printInteger) -(void)printSet; @end @implementation NSSet(printInteger) -(void)printSet { for (NSNumber *integer in self) { printf("%i",[integer integerValue]); } printf(" "); } @end int main(void) { @autoreleasepool { NSMutableSet *set1=[NSMutableSet setWithObjects:[NSNumber numberWithInteger:1], [NSNumber numberWithInteger:3], [NSNumber numberWithInteger:5], nil]; NSMutableSet *set2=[NSMutableSet setWithObjects:[NSNumber numberWithInteger:2], [NSNumber numberWithInteger:4], [NSNumber numberWithInteger:6], nil]; if ([set1 isEqualToSet:set2]==YES) { NSLog(@"set1=set2"); }else{ NSLog(@"set1!=set2"); } if ([set1 containsObject:[NSNumber numberWithInteger:3]]==YES) { NSLog(@"set1 included 3"); }else{ NSLog(@"set1 not included 3"); } [set1 printSet]; [set1 addObject:[NSNumber numberWithInteger:6]]; [set1 removeObject:[NSNumber numberWithInteger:1]]; [set1 printSet]; [set1 intersectSet:set2]; [set1 printSet]; [set1 intersectSet:set2]; [set1 printSet]; [set1 unionSet:set2]; [set1 printSet]; } return 0; }