oc 字典

#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

 

posted @ 2015-08-18 14:12  netcorner  阅读(215)  评论(0编辑  收藏  举报