1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
// // main.m // NSMutableDictionary // #import <Foundation/Foundation.h> #import "Pepole.h" //引入外部文件的方法:右键项目-》Add files to ...-》选择文件并选择copy文件 //引入如果出现编译问题(link error),1.Product->clean;2.左击项目-》build phases->compaile sources->添加刚加入的m文件 void mdict(){ //创建一个空字典 NSMutableDictionary *dict = [NSMutableDictionary dictionary]; //向字典中添加元素 Pepole *p1 =[Pepole pepoleWithName:@"p1"]; [dict setObject:p1 forKey:@"key1"]; [dict removeObjectForKey:@"key1"];//删除指定的字典元素 [dict removeAllObjects];//删除所有的字典元素 [dict addEntriesFromDictionary:[NSDictionary dictionaryWithObject:p1 forKey:@"p2"]];//把字典添加到字典中 NSLog(@"dict is %@", dict); } int main(int argc, const char * argv[]) { @autoreleasepool { mdict(); } return 0; } |