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

来源:互联网 发布:ubuntu安装搜狗 编辑:程序博客网 时间:2024/06/10 19:04
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];

0 0