To be or not to be.That is a question!

---源于莎士比亚的《哈姆雷特》

导航

集合对象(NSSet)

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("\n");
}

@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;
}

 

posted on 2013-09-22 10:52  Ijavascript  阅读(247)  评论(0编辑  收藏  举报