首页 > 代码库 > NSSet -- 集合&&NSMutableSet -- 可变集合

NSSet -- 集合&&NSMutableSet -- 可变集合

//
//  main.m
//  OC05-task-03
//
//  Created by Xin the Great on 15-1-25.
//  Copyright (c) 2015年 Xin the Great. All rights reserved.
//

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        // insert code here...
        ///////////////NSSet -- 集合////////////////
        
        //不可变
        
        //集合没有重复的元素,而且无序
        NSSet *set = [[NSSet alloc] initWithObjects:@"a",@"b",@"a", nil];
        NSLog(@"set is %@",set);
        
        //类方法初始化
        NSSet *set1 = [NSSet setWithObjects:@"1",@"2",@"x",@"y", nil];
        NSLog(@"set1 is %@",set1);

        
        //获取集合元素的个数
        NSUInteger count = [set1 count];
        NSLog(@"count is %ld", count);
        
        //获取所有的集合元素
        NSArray *list = [set1 allObjects];
        NSLog(@"list is %@", list);
        
        //获得任意一个元素
        id value = http://www.mamicode.com/[set1 anyObject];>

NSSet -- 集合&&NSMutableSet -- 可变集合