代码改变世界

NSSet

2016-12-16 08:53  supper_Ho  阅读(227)  评论(0编辑  收藏  举报

//

//  main.m

//  09-集合

//

//  Created by apple on 14-3-21.

//  Copyright (c) 2014年 apple. All rights reserved.

//

 

#import <Foundation/Foundation.h>

 

int main(int argc, const char * argv[])

{

 

    @autoreleasepool {

        

        //NSArray 自然顺序

        //NSSet是无序的

        //注意:这个是最为重要的功能 NSSet中不能够存储重复的数据,可以用它来去除重复的值

        NSString * str1 = @"one";

        NSString * str2 = @"two";

        NSString * str3 = @"three";

        NSSet * set = [[NSSet alloc] initWithObjects:str1,str2,str3,str1, nil];

        NSLog(@"set %@",set);

        

        //count

        NSLog(@"count %ld",set.count);

        

       BOOL isContains =  [set containsObject:str1];

        if (isContains)

        {

            NSLog(@"YES");

        }

        else

        {

            NSLog(@"NO");

        }

        

        //4.遍历

        

        NSEnumerator * enumerator = [set objectEnumerator];

        NSString * value;

        while (value = [enumerator nextObject]) {

            NSLog(@"value %@",value);

        }

        

    }

    return 0;

}