蓝鸥iOS从零基础到精通就业-OC语言入门 集合

  • iOS从零基础到精通就业 Objective-C

  • CSDN观看地址:http://edu.csdn.net/course/detail/3347
  • 集合
  • #import <Foundation/Foundation.h>
    
    int main(int argc, const char * argv[]) {
       
        
        //不可变集合
        //跟字典一样没有顺序
        //去除重复的元素
        //NSSet *set1 = [[NSSet alloc] initWithObjects:<#(nonnull id), ...#>, nil];
        NSSet *set1 = [NSSet setWithObjects:@"aaa",@"bbb",@"ccc",@"ddd",@"aaa",@"ccc", nil];
        NSLog(@"%@",set1);
        //获取集合中的元素
        NSString *str = [set1 anyObject];
        NSLog(@"%@",str);
        
        //可变集合
        NSMutableSet *mSet = [NSMutableSet set];
        [mSet addObject:@"1111"];
        [mSet addObject:@"2222"];
        [mSet addObject:@"3333"];
        [mSet addObject:@"4444"];
        [mSet addObject:@"1111"];
        NSLog(@"%ld",[mSet count]);
        
        [mSet removeObject:@"3333"];
        NSLog(@"%ld",[mSet count]);
        
        //计数集合
        NSCountedSet *cSet = [NSCountedSet set];
        [cSet addObject:@"1111"];
        [cSet addObject:@"2222"];
        [cSet addObject:@"3333"];
        [cSet addObject:@"4444"];
        [cSet addObject:@"1111"];
        [cSet addObject:@"1111"];
        [cSet addObject:@"2222"];
        [cSet addObject:@"1111"];
        [cSet addObject:@"1111"];
        NSLog(@"%ld",[cSet countForObject:@"1111"]);
        
        
        int a = 10;
        int b = 20;
        NSString *astr = [NSString stringWithFormat:@"%d",a];
        NSString *bstr = [NSString stringWithFormat:@"%d",b];
        
        NSArray *array = [NSArray arrayWithObjects:astr,bstr, nil];
        
        NSString *result = [array objectAtIndex:0];
        int a1 = [result intValue];
        NSLog(@"%d",a1);
        
        float f1 = 9.99;
        NSNumber *n1 = [NSNumber numberWithFloat:f1];
        NSArray *array1 = @[n1];
        NSNumber *resultNumer = array1[0];
        float resultFloat = [resultNumer floatValue];
        
        return 0;
    }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值