当前位置:网站首页>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”;
边栏推荐
猜你喜欢
随机推荐
Find the largest n files
有关 sql中的 concat()函数问题,如何拼接
FormData上传二进制文件、对象、对象数组
CSRF-跨站请求伪造-相关知识
LeetCode 2360. 图中的最长环
sql 远程访问链接服务器
企业实训复现指导手册——基于华为ModelArts平台的OpenPose模型的训练和推理、基于关键点数据实现对攀爬和翻越护栏两种行为的识别、并完成在图片中只标注发生行为的人
Splunk Field Caculated 计算字段
LeetCode 2312. 卖木头块
WebGPU 导入[2] - 核心概念与重要机制解读
LeetCode刷题(7)
LeetCode 283. 移动零(简单、数组)
MQ带来的一些问题、及解决方案
【机器学习】实验1布置:基于决策树的英雄联盟游戏胜负预测
Splunk Filed extraction 字段截取
反射课后习题及做题记录
查看端口号占用
逆变器绝缘检测检测功能及软件实现
自然语言处理 文本预处理(下)(张量表示、文本数据分析、文本特征处理等)
【ROS基础】map、odom、base_link、laser 的理解 及其 tf 树的理解








——设备树的概述(硬件、目标、效果、文件类型)](/img/c6/6c2321bfcd184886e1cb59664bec11.png)
