首页 > 其他 > 详细

oc 字典

时间:2015-08-18 15:45:42      阅读:193      评论:0      收藏:0      [点我收藏+]
#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

 

oc 字典

原文:http://www.cnblogs.com/netcorner/p/4739263.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!