NSMutableDictionary

简介:
 1 //  2 //  main.m  3 //  NSMutableDictionary  4 //  5 //  Created by dingxiaowei on 13-5-16.  6 //  Copyright (c) 2013年 dingxiaowei. All rights reserved.  7 //  8   9 #import <Foundation/Foundation.h> 10 #import "Student.h"    //特别注意:如果从外部导入的类文件,则需要在问价里面看有没有对它进行添加到项目中  在这儿的操作是:首先点击蓝色的项目文件-》然后点击第二个Build Phases-》接着查看compile Items 看看里面是否包含外部导入进来的那个类的.m文件 11  12 #pragma mark - 字典的创建 13 void dicCreat(){ 14     Student *stu1=[Student studentWithName:@"dingxiaowei"]; 15     Student *stu2=[Student studentWithName:@"hanpengyu"]; 16     Student *stu3=[Student studentWithName:@"jiangke"]; 17     NSMutableDictionary *dic=[NSMutableDictionary dictionaryWithObjectsAndKeys:stu1,@"k1",stu2,@"k2",stu3,@"k3",nil]; 18     //直接添加键值对 19     [dic setObject:@"value" forKey:@"key"]; 20     //根据一个key删除一个键值对 21     [dic removeObjectForKey:@"key"]; 22     //根据key查找value(如果找不到,则返回null) 23     NSLog(@"%@",[dic objectForKey:@"key"]); 24     //删除多个key对应的value 25     [dic removeObjectsForKeys:[NSArray arrayWithObjects:@"k1",@"k2",nil]]; 26     //将另外一个dictionary添加到当前dictionary中 27     NSDictionary *dicOther=[NSDictionary dictionaryWithObjectsAndKeys:@"valueOne",@"keyOne",@"valueTwo",@"keyTwo",nil]; 28     [dic addEntriesFromDictionary:dicOther]; 29     NSLog(@"%@",dic); 30 } 31  32 int main(int argc, const char * argv[]) 33 { 34  35     @autoreleasepool { 36         dicCreat(); 37          38     } 39     return 0; 40 }















,如需转载请自行联系原作者

相关文章
|
Windows
NSString的boolValue方法甚解
前言 NSString的boolValue之前有使用,但是一直没有真正了解什么时候返回YES(true)或NO(false)。其实,苹果在官方文档中已经写的很清楚,按command + control 点击boolValue进入文档就可以看到: boolValue The Boolean value of the string.
910 0
|
XML 数据格式
|
机器学习/深度学习 C语言 索引
|
存储 Android开发 自然语言处理