#import <UIKit/UIKit.h> #import "AppDelegate.h" int main(int argc, char * argv[]) { //固定的字典类型 NSDictionary *dict=@{@"name":@"Netcorner",@"sex":@"male"}; NSLog(@"%@",dict); //读取字典类型的文件 NSDictionary *dict1=[NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"data" ofType:@"plist"]];//NSBundle用于读取资源文件 NSLog(@"%@",dict1); NSLog(@"%@",[dict1 objectForKey:@"name"]); //可变的字典类型 NSMutableDictionary *mdict=[[NSMutableDictionary alloc] init]; [mdict setObject:@"stephen" forKey:@"name"];//设置字典 NSLog(@"%@",mdict); }
data.plist内容如下:
注:oc中的可变字典相当于java中的map