Xocde新特性--NSDictionary&&NSArray

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        NSArray *arr1 = [NSArray arrayWithObjects:@"one",@"tow", nil];
        //等价于
        NSArray *arr2 = @[@"one",@"two"];//不可变数组才有这种特性
        NSLog(@"%@ %@",arr1,arr2);
        
        
        NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:@"1",@"one",@"2",@"two", nil];
        NSLog(@"dict:%@",dict);

        NSDictionary *dict2 = @{@"one": @"1",@"two":@"2"};
        NSLog(@"dict2:%@",dict2);
        //NSString *str = [dict2 objectForKey:@"one"];
        //等价于新特性
        NSString * str = dict2[@"one"];
        NSLog(@"str:%@",str);//str:1
        
        
    }
    return 0;
}


你可能感兴趣的:(xcode,新特性)