ios学习第1章:实现控制器和视图-基础变化

NSInteger myNumber = -20;

    
    
NSString *myString = @"Objective-C is great!";
数组初始化

    
    
 NSArray *stringsArray = @[
                              @"String 1"

];

    __unused NSString *firstString = stringsArray[0];

    
    
 NSString *string1 = @"String 1";
    NSString *string2 = @"String 2";
    NSString *string3 = @"String 3";
    NSArray *immutableArray = @[string1, string2, string3];
    NSMutableArray *mutableArray = [[NSMutableArray alloc]
                                    initWithArray:immutableArray];
    [mutableArray exchangeObjectAtIndex:0 withObjectAtIndex:1];
    [mutableArray removeObjectAtIndex:1];
    [mutableArray setObject:string1 atIndexedSubscript:0];

字典初始化

    
    
  NSDictionary *personInformation =
    @{
      @"firstName" : @"Mark",
      @"lastName" : @"Tremonti",
      @"age" : @30,
      @"sex" : @"Male"

};

    NSString *firstName = personInformation[@"firstName"];
集合初始化1

        
        
    NSSet *shoppingList = [[NSSet alloc] initWithObjects:
                           @"Milk",
                           @"Bananas",
                           @"Bread",
                           @"Milk", nil];
    NSMutableSet *mutableList = [NSMutableSet setWithSet:shoppingList];
    [mutableList addObject:@"Yogurt"];
    [mutableList removeObject:@"Bread"];
//集合初始化2

          
          
 NSSet *setOfNumbers = [NSSet setWithArray:@[@3, @4, @1, @5, @10]];
    NSLog(@"Set of numbers = %@", setOfNumbers);

 NSMutableOrderedSet *setOfNumbers =
        [NSMutableOrderedSet orderedSetWithArray:@[@3, @4, @1, @5, @10]];
    [setOfNumbers removeObject:@5];
    [setOfNumbers addObject:@0];
    [setOfNumbers exchangeObjectAtIndex:1 withObjectAtIndex:2];

NSLog(@"Count for object @10 = %lu",
(
unsigned long)[setOfNumbers countForObject:@10]); 



    
    

NSString *const kFirstNameKey = @"firstName";NSString *const kLastNameKey = @"lastName";

    NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
[dictionary setValue:@"Tim" forKey:kFirstNameKey];
    [dictionary setValue:@"Cook" forKey:kLastNameKey];
    __unused NSString *firstName = [dictionary valueForKey:kFirstNameKey];
    __unused NSString *lastName = [dictionary valueForKey:kLastNameKey];

    
    

SString *const kFirstNameKey = @"firstName";NSString *const kLastNameKey = @"lastName";

    NSDictionary *dictionary = @{
                                 kFirstNameKey : @"Tim",
                                 kLastNameKey : @"Cook",
                                 };
    __unused NSString *firstName = dictionary[kFirstNameKey];
    __unused NSString *lastName = dictionary[kLastNameKey];
NSArrary>>>>

    
    
 NSArray *array = [[NSArray alloc] initWithObjects:@"Tim", @"Cook", nil];
    __unused NSString *firstItem = [array objectAtIndex:0];
    __unused NSString *secondObject = [array objectAtIndex:1];

    NSArray *array = @[@"Tim", @"Cook"];
    __unused NSString *firstItem = array[0];
    __unused NSString *secondObject = array[0];





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值