当前位置:网站首页>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”;
边栏推荐
猜你喜欢
随机推荐
有趣的网站
2020美亚团队赛复盘
【图像隐藏】基于matlab混合DWT-HD-SVD数字图像水印方法技术【含Matlab源码 2007期】
【机器学习】实验1布置:基于决策树的英雄联盟游戏胜负预测
FormData上传二进制文件、对象、对象数组
实例032:反向输出II
Splunk Filed Alias 字段改名
Resolving C# non-static field, method or property "islandnum.Program.getIslandCount(int[][], int, int)" requires an object reference
LeetCode 283. 移动零(简单、数组)
你认同这个观点吗?大多数企业的数字化都只是为了缓解焦虑
sql 远程访问链接服务器
Mysql报错2003 解决办法 Can‘t connect to MySQL server on ‘localhost‘ (10061)
在VMware上安装Metasploitable2
查找最大的n个文件
自然语言处理 文本预处理(下)(张量表示、文本数据分析、文本特征处理等)
从云计算到函数计算
Vscode connect to remote server "Acquiring the lock on the/home / ~ 'problem
自然语言处理 文本预处理(上)(分词、词性标注、命名实体识别等)
使用hutool做本地缓存的工具类
【红队】ATT&CK - 创建或修改系统进程实现持久化(更新ing)









