当前位置:网站首页>OC-NSDictionary
OC-NSDictionary
2022-08-02 06:50:00 【彭同学她同桌】
#NSDictionary
初始化
//方法一
NSDictionary *dict = [[NSDictionary alloc]initWithObjectsAndKeys:@"value1",@"key1",@"value2",@"key2",nil];
NSLog(@"%@",dict);//如果键值对数量不匹配则会崩溃
//方法二 就是可以通过数组来进行初始化
NSDictionary*dict2 = [NSDictionary dictionartWithObjects:@[@"value1",@"value2"] forKeys:@[@"key1",@"key2"]];
NSLog(@"%@",dict2);
NSDictionary*dict2 = @{
@"k1":@"v1",
@"k2":@"v2"};//注意这里 必须是先k再v
查
//直接通过key值获取val值
NSLog(@“%@”,dict3[@"k2"]);
//直接循环获取key值
for(NSString *string in dict3)
{
NSLog(@"%@ %@",string,dict3[string]);
}
//直接用数组获取所有key值
NSArray* array = [dict3 allKeys];
NSLog(@"%@",array);// k1,k2
//直接用数组获取所有key值
NSArray* array1 = [dict3 allValues];
NSLog(@"%@",array1);// v1,v2
NSMutableDictionary
初始化
NSMutableDictionary* dict = [NSMutableDictionary dictionary];
dict[@“k1”] = @“v1”;
边栏推荐
- 电商库存系统的防超卖和高并发扣减方案
- Swagger的简单介绍,集成,以及如何在生产环境中关闭swagger,在测试和开发环境中自动打开
- At age 94, pioneer Turing award winner, computational complexity theory, Juris Hartmanis, died
- Resolving C# non-static field, method or property "islandnum.Program.getIslandCount(int[][], int, int)" requires an object reference
- See the picture to understand | How to choose sales indicators to measure the health of business growth
- C#重点问题之Struct和Class的异同
- FaceBook社媒营销高效转化技巧分享
- [npm install error report collection] - npm ERR! code ENOTEMPTY npm ERR! syscall rmdir
- 论文阅读 (64):Weakly-supervised Video Anomaly Detection with Robust Temporal Feature Magnitude Learning
- 从云计算到函数计算
猜你喜欢

聊天机器人如何提升独立站的营销水平?

Gradle系列——Gradle插件(基于Gradle文档7.5)day3-2

条件构造器~wapper

See the picture to understand | How to choose sales indicators to measure the health of business growth

【故障诊断分析】基于matlab FFT轴承故障诊断(包络谱)【含Matlab源码 2002期】

在VMware上安装Metasploitable2

数据库概论之MySQL表的增删改查2

Analysis of GCC compiler technology

【图像去噪】基于matlab双立方插值和稀疏表示图像去噪【含Matlab源码 2009期】

第06章 索引的数据结构【2.索引及调优篇】【MySQL高级】
随机推荐
Redis 常用命令和基本数据结构(数据类型)
[npm install error report collection] - npm ERR! code ENOTEMPTY npm ERR! syscall rmdir
倍福使用AdsRemote组件实现和C#的ADS通讯
Clapper that can interact with the audience in real time
牛客编程题中——需要处理输入较大数的题目
gdalinfo: error while loading shared libraries: libgdal.so.30: cannot open shared object file: No su
MySQL-FlinkCDC-Hudi实时入湖
张驰课堂:六西格玛培训工具——箱线图
有趣的网站
Unity Shader学习(七)纹理图像的简单使用
MPLS的相关技术
获取间隔的日期列表工具类
(2022牛客多校五)B-Watches(二分)
HCIP day one
awk语法-01-基础语法(命令、选项、内部变量)
【CV】OpenVINO安装教程
PWA 踩坑 - 第一次加载页面后无法获取CacheStorage某些资源
How does abaqus quickly import the assembly of other cae files?
hdu1752 copy
CSRF-跨站请求伪造-相关知识