NSDictionary的基本使用
////main.m
//NSDictionary
//
//Created by yusian on 14-3-23.
//Copyright (c) 2014年 小龙虾论坛. All rights reserved.
//
#import <Foundation/Foundation.h>
int main()
{
// 字典的几种赋值方式:
// 1、直接使用类名方法初始化,内容为空
// NSDictionary * dict = ;
// 2、调用类方法dictionaryWithObject:
// NSDictionary *dict = ;
// 3、调用类方法传数组分别做为Objects与Keys
// NSArray *objs = @[@"yusian", @"27"];
// NSArray *keys = @[@"name", @"age"];
// NSDictionary *dict = ;
// 4、使用类方法同时传键值对
/* NSDictionary * dict = [NSDictionary dictionaryWithObjectsAndKeys:
@"yusian", @"name",
@"27", @"age", nil];*/
// 5、使用编译器特性
NSDictionary *dict = @{@"name" : @"yusian", @"age" : @"27"};
// 6、输出整个字典
// NSLog(@"%@", dict);
// 7、输出字典中的某个值
// 通过方法取
// id obj = ;
// 通过编译器特性,类似数组的取值方式实现
id obj = dict[@"name"];
NSLog(@"%@", obj);
return 0;
}
页:
[1]