码迷,mamicode.com
首页 > 其他好文 > 详细

Xocde新特性--NSDictionary&&NSArray

时间:2015-10-21 22:51:47      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:

#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;
}


Xocde新特性--NSDictionary&&NSArray

标签:

原文地址:http://my.oschina.net/u/2410306/blog/520043

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!