zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    代码块&继承&final关键字
    Java基础
    我的学习笔记
    CF743C 题解
    洛谷P4180 题解
    洛谷P3402 题解
    洛谷P3919 题解
    Noi.ac#30 题解
    Noi.ac #65题解
    Noi.ac #51题解
  • 原文地址:https://www.cnblogs.com/netcorner/p/4739263.html
Copyright © 2011-2022 走看看