NSMutableDictionary
2015-06-04 16:15
246 查看
//NSMutableDictionary
#import “Student.h”
#pragma mark use of NSMutableDictionary
void dictUse(){
Student *stu1=[Student studentWithName:@”stu1”];
Student *stu2=[Student studentWithName:@”stu2”];
//create a mutable void dict
NSMutableDictionary *dict=[NSMutableDictionary dictionary];
//add elements
//add student class
//Way1:
//If not check that ,in current project only quote
//if just quote ,never check move to trash,it will delete original file.
//Way2
//Select the files and move to your current project
//Personal opinion better copy
[dict setObject:stu1 forKey:@“k1”];//counter=2
NSLog(@”stu1:zi%”,[stu1 retainCount]);
[dict setObject:stu2 forKey:@”k2”];
}
//check which files are added to your project
//Tips
//If you import some files from outside,check whether they are compiled.
//When the dict is destroied , all the keys and values inside will be reduce counter
//Add content of other dictionary into current dictionary
NSDictory *other=[NSDictionary dictionaryWithObject:@”v2” forKey:@”k2”];
[dict addEntriesFromDictionary:other];
//delete element
[dict removeAllObjects];// Remove all keys and values
[dict removeObjectForKey:@”k1”];
// remove object according to key stu1
//Remove objects base on multi-keys
[dict removeObjectsForKeys:[NSArray arrayWithObject:@”k1”]];
#import “Student.h”
#pragma mark use of NSMutableDictionary
void dictUse(){
Student *stu1=[Student studentWithName:@”stu1”];
Student *stu2=[Student studentWithName:@”stu2”];
//create a mutable void dict
NSMutableDictionary *dict=[NSMutableDictionary dictionary];
//add elements
//add student class
//Way1:
//If not check that ,in current project only quote
//if just quote ,never check move to trash,it will delete original file.
//Way2
//Select the files and move to your current project
//Personal opinion better copy
[dict setObject:stu1 forKey:@“k1”];//counter=2
NSLog(@”stu1:zi%”,[stu1 retainCount]);
[dict setObject:stu2 forKey:@”k2”];
}
//check which files are added to your project
//Tips
//If you import some files from outside,check whether they are compiled.
//When the dict is destroied , all the keys and values inside will be reduce counter
//Add content of other dictionary into current dictionary
NSDictory *other=[NSDictionary dictionaryWithObject:@”v2” forKey:@”k2”];
[dict addEntriesFromDictionary:other];
//delete element
[dict removeAllObjects];// Remove all keys and values
[dict removeObjectForKey:@”k1”];
// remove object according to key stu1
//Remove objects base on multi-keys
[dict removeObjectsForKeys:[NSArray arrayWithObject:@”k1”]];
相关文章推荐
- Android 学习笔记 Service
- tar打包、压缩与解压缩到指定目录的方法
- Execution和ProcessInstance的分别
- Win2003 Enterprise x64 Edition漏洞下载地址
- 幼教互动云平台
- Windows库程序之动态库程序
- 小鹰展翅-虚基类
- Java socket多线程示例
- hdu5249KPI动态中位数(两个set)
- 希尔排序
- leetcode_90题——Subsets II (递推)
- Xml转化为DataTable
- 使用Chrome测试页面响应性
- 利用百度SDK进行城市定位
- GRE填空中介词的常用搭配
- iOS应用架构谈 view层的组织和调用方案
- easyUI 1.3.2 dataGrid动态绑定列名和数据
- 黑马程序员_内存管理小结
- 修改 mysql 的字符编码
- Reverse Nodes in k-Group