当前位置:网站首页>OC-NSDictionary
OC-NSDictionary
2022-08-02 07:49:00 【Classmate Peng, she is at the same table】
#NSDictionary
初始化
//方法一
NSDictionary *dict = [[NSDictionary alloc]initWithObjectsAndKeys:@"value1",@"key1",@"value2",@"key2",nil];
NSLog(@"%@",dict);//Crashes if the number of key-value pairs does not match
//方法二 It can be initialized through an array
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]);
}
//Get all directly with the arraykey值
NSArray* array = [dict3 allKeys];
NSLog(@"%@",array);// k1,k2
//Get all directly with the arraykey值
NSArray* array1 = [dict3 allValues];
NSLog(@"%@",array1);// v1,v2
NSMutableDictionary
初始化
NSMutableDictionary* dict = [NSMutableDictionary dictionary];
dict[@“k1”] = @“v1”;
边栏推荐
- OC-错误提示
- 【机器学习】课程设计布置:某闯关类手游用户流失预测
- 有关 sql中的 concat()函数问题,如何拼接
- OC-NSNumber and NSValue are generally used for boxing and unboxing
- 逆变器绝缘检测检测功能及软件实现
- 2022.07.31(LC_6132_使数组中所有元素都等于零)
- Find the largest n files
- OC-NSNumber和NSValue一般用来装箱拆箱
- PWA 踩坑 - 第一次加载页面后无法获取CacheStorage某些资源
- 【故障诊断分析】基于matlab FFT轴承故障诊断(包络谱)【含Matlab源码 2002期】
猜你喜欢
随机推荐
Swagger的简单介绍,集成,以及如何在生产环境中关闭swagger,在测试和开发环境中自动打开
正则表达式
FormData上传二进制文件、对象、对象数组
_2_顺序表
C#重点问题之Struct和Class的异同
【暑期每日一题】洛谷 P3156 【深基15.例1】询问学号
埋点开发流程
spark读取文件夹数据
(Part of it is not understood, and the notes are not completed) [Graph Theory] Difference Constraints
有关 sql中的 concat()函数问题,如何拼接
Vscode connect to remote server "Acquiring the lock on the/home / ~ 'problem
暑假第五周总结
飞桨paddle技术点整理
OC-范畴
根据一个字段的内容去更新另一个字段的数据,这样的sql语句该怎么样书写
【ROS基础】rosbag 的使用方法
optional
张驰课堂:六西格玛培训工具——箱线图
Splunk Filed extraction 字段截取
敏捷、DevOps和嵌入式系统测试