当前位置:网站首页>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”;
边栏推荐
- Leetcode Weekly 304
- 暑假第五周总结
- 根据一个字段的内容去更新另一个字段的数据,这样的sql语句该怎么样书写
- SQL server 2014 怎么一次性导出多个查询结果?
- The nacos source code can not find the istio package
- Vscode连接远程服务器出现‘Acquiring lock on/home/~’问题
- Unity Shader学习(七)纹理图像的简单使用
- Wuhan 2022 organizing of the high-performance computing added new ecological development of high-performance computing
- 【暑期每日一题】洛谷 P1192 台阶问题
- [21天学习挑战赛——内核笔记](一)——设备树的概述(硬件、目标、效果、文件类型)
猜你喜欢
第06章 索引的数据结构【2.索引及调优篇】【MySQL高级】
Pagoda+FastAdmin 404 Not Found
Redis 常用命令和基本数据结构(数据类型)
The nacos source code can not find the istio package
(部分不懂,笔记整理未完成)【图论】差分约束
HCIP day 3 experiment
逆变器绝缘检测检测功能及软件实现
论文《Deep Multifaceted Transformers for Multi-objective Ranking in Large-Scale E-commerce Recommender》
数据库概论-MySQL的数据表的基本操作
21 days learning challenge 】 【 sequential search
随机推荐
[Dataset][VOC] Male and female dataset voc format 6188 sheets
实例027:递归输出
【机器学习】实验4布置:AAAI会议论文聚类分析
海缆探测仪TSS350(二)
技术管理三级跳
在VMware上安装Metasploitable2
结构体大小计算--结构体内存对齐
以训辅教,以战促学 | 新版攻防世界平台正式上线运营!
2022.07.31(LC_6133_分组的最大数量)
HCIP day one
张驰咨询:企业实施精益管理的最大障碍,只把精益作为一种工具和方法
飞桨paddle技术点整理
暑假第五周总结
About the local server problem after ue4.27 pixel streaming package
【网络】IP、子网掩码
See the picture to understand | How to choose sales indicators to measure the health of business growth
MQ带来的一些问题、及解决方案
【暑期每日一题】洛谷 P1255 数楼梯
LeetCode 283. 移动零(简单、数组)
Project development specification