当前位置:网站首页>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”;
边栏推荐
猜你喜欢
Xilinx约束学习笔记—— 时序约束
LeetCode 2360. The longest cycle in a graph
以训辅教,以战促学 | 新版攻防世界平台正式上线运营!
图腾柱和推挽电路介绍
mysql操作入门(四)-----数据排序(升序、降序、多字段排序)
张驰课堂:六西格玛测量系统的误差分析与判定
论文《Deep Multifaceted Transformers for Multi-objective Ranking in Large-Scale E-commerce Recommender》
交换--STP协议
【故障诊断分析】基于matlab FFT轴承故障诊断【含Matlab源码 2001期】
根据一个字段的内容去更新另一个字段的数据,这样的sql语句该怎么样书写
随机推荐
实例028:递归求等差数列
实例029:反向输出
CollectionUtil:一个函数式风格的集合工具
有关 sql中的 concat()函数问题,如何拼接
(2022牛客多校五)D-Birds in the tree(树形DP)
交换部分 VLAN
【云原生】如何快速部署Kubernetes
Go 实现分布式锁
以训辅教,以战促学 | 新版攻防世界平台正式上线运营!
spark架构
OC - NSSet (set)
Redis 常用命令和基本数据结构(数据类型)
Link with Game Glitch(spfa判负环)
sql 远程访问链接服务器
2022.07.31(LC_6132_使数组中所有元素都等于零)
正则表达式
【机器学习】实验1布置:基于决策树的英雄联盟游戏胜负预测
牛客编程题中——需要处理输入较大数的题目
(2022牛客多校五)C-Bit Transmission(思维)
技术管理三级跳