OC之Foundation框架NSSet

//
//  main.m
//  NSSet
//
//  Created by New-World on 13-11-2.
//  Copyright (c) 2013年 Gary. All rights reserved.
//

#import <Foundation/Foundation.h>

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

    @autoreleasepool {
        NSSet *set0=[[NSSet alloc] initWithObjects:@"1",@"2",@"3", nil];
        NSSet *set1=[NSSet setWithObjects:@"a",@"d",@"f",nil];
        NSArray *array=[NSArray arrayWithObjects:@"a",@"d", nil];
        NSSet *set2=[NSSet setWithArray:array];
        NSSet *set4=[NSSet setWithSet:set1];
        NSLog(@"set0:%@",set0);
        NSLog(@"set1:%@",set1);
        NSLog(@"set2:%@",set2);
        NSLog(@"set4:%@",set4);
        
        unsigned long count=[set0 count];//集合中的对象个数
        NSArray *allObjects=[set0 allObjects];//以数组的形式返回set0的对象
        id object =[set0 anyObject];//获取set0中的任意对象
        BOOL isContain=[set1 containsObject:@"f"];//set1中是否包含f
        BOOL isInterset=[set0 intersectsSet:set1];//set0与set1是否包含相同元素对象
        BOOL isEqual=[set0 isEqualToSet:set1];//set0与set1是否完全相同
        BOOL isSubset=[set2 isSubsetOfSet:set1];//set2是否是set1的子集
        for (NSString *s in allObjects) {
            NSLog(@"s:%@",s);
        }
        NSLog(@"count: %ld",count);
        NSLog(@"object:%@",object);
        NSLog(@"set0是否包含:%d",isContain);
        NSLog(@"set0,set1是否存在交集:%d",isInterset);
        NSLog(@"set0,set1是否完全相同:%d",isEqual);
        NSLog(@"set2是否是set1的子集:%d",isSubset);
        
        
        NSSet *set5=[NSSet setWithObjects:@"one", nil];
        NSSet *appset1=[set5 setByAddingObject:@"two"];
        
        NSLog(@"appset:%@",appset1);
        NSSet *appset2=[set5 setByAddingObjectsFromSet:set0];
        NSLog(@"appset2:%@",appset2);
        
        NSArray *array2=[NSArray arrayWithObject:@"end"];
        NSSet *appset3=[set5 setByAddingObjectsFromArray:array2];
        NSLog(@"appset3:%@",appset3);
        
        //-------------------NSMutableSet----------------------
        NSMutableSet *mset1=[NSMutableSet setWithObjects:@"1",@"2", nil];
        NSMutableSet *mset2=[NSMutableSet setWithObjects:@"1",@"3", nil];
        //减去相同的内容
        [mset2 minusSet:mset1];
        //两个set的交集
        [mset2 intersectSet:mset1];
        //并集
        [mset1 unionSet:mset1];
        
        [mset2 removeObject:@"1"];
        [mset1 removeAllObjects];
        
        
        
        }
    
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值