【深入浅出Objective-C】8.3字典(NSMutableDictionary)
来源:互联网 发布:python while循环列表 编辑:程序博客网 时间:2024/05/29 16:17
#import <Foundation/Foundation.h>int main(int argc, const char * argv[]){ @autoreleasepool { NSDictionary *aDict = [NSDictionary dictionaryWithObject:@"value1" forKey:@"key1"]; NSDictionary *bDict = [[NSDictionary alloc]initWithObjects:[NSArray arrayWithObjects:@"coooliang",@"20",@"fz", nil] forKeys:[NSArray arrayWithObjects:@"name",@"age",@"city", nil]]; NSLog(@"aDict = %@",aDict); NSLog(@"bDict = %@",bDict); //此处使用objectForKey和valueForKey结果相同 //键名不为NSString的时候,只能使用objectForKey,valueForKey键值只能是NSString id name = [bDict objectForKey:@"name"]; if([name isKindOfClass:[NSString class]]){ NSLog(@"objectForKey name = %@",name); } id age = [bDict valueForKey:@"age"]; if([age isKindOfClass:[NSString class]]){ NSLog(@"valueForKey age = %@",age); } //遍历 NSEnumerator *aEnum = [bDict objectEnumerator]; id oneObj = nil; while (oneObj = [aEnum nextObject]) { if([oneObj isKindOfClass:[NSString class]]){ NSLog(@"%@",oneObj); } } //访问所有键名和值以及配合NSDictionary NSLog(@"allkey = %@",[bDict allKeys]); NSLog(@"allValue = %@",[bDict allValues]); //NSError *error = nil; //NSDictionary *fileDict = [[NSFileManager alloc]attributesOfFileSystemForPath:@"path" error:&error]; //可变数组 NSMutableDictionary *maDict = [NSMutableDictionary dictionaryWithCapacity:0]; NSMutableDictionary *mbDict = [[NSMutableDictionary alloc]initWithObjects:[NSArray arrayWithObjects:@"a",@"b", nil] forKeys:[NSArray arrayWithObjects:@"va",@"vb", nil]]; [maDict addEntriesFromDictionary:mbDict]; [maDict setObject:@"c" forKey:@"vc"]; NSLog(@"maDict = %@",maDict); [maDict removeAllObjects]; NSLog(@"remove a %@",maDict); NSLog(@"remove after b %@",mbDict); } return 0;}
0 0
- 【深入浅出Objective-C】8.3字典(NSMutableDictionary)
- Objective-c 字典对象 (NSDictionary 和 NSMutableDictionary )
- Objective-C 字典:"NSDictionary" 和 "NSMutableDictionary"
- Objective-C语法-字典NSDictionary和可变字典NSMutableDictionary
- 字典对象(NSDictionary 和 NSMutableDictionary)-Objective-C
- Objective-C ,ios,iphone开发基础:NSDictionary(字典) 和 NSMutableDictionary
- 字典对象(NSDictionary 和 NSMutableDictionary)-Objective-C
- Objective-C学习-字典类型 NSDictionary 和 NSMutableDictionary
- Objective-C------NSDictionary、NSMutableDictionary字典对象用法总结
- Objective-C语言——NSMutableDictionary可变字典
- Objective-C 字典的基本用法(NSDictionary和NSMutableDictionary)
- NSMutableDictionary操纵字典内容(Objective-C 开发范例)
- objective-c NSMutableDictionary 使用
- Objective-c - NSDictionary(NSMutableDictionary)
- Objective-C----NSDictionary、NSMutableDictionary
- Objective-C中的NSDictionary/NSMutableDictionary
- Objective-c的Foundation中常用类4——字典NSDictionary、NSMutableDictionary
- 【Objective-C】OC中字典基本概念和常用方法(NSDictionary和NSMutableDictionary)
- [MST]POJ 1258Agri-Net
- 阿里云服务器的80端口被封了么?
- javascript的中文传参
- 1039. Course List for Student (25)
- <MEMORY>Project Euler NO55
- 【深入浅出Objective-C】8.3字典(NSMutableDictionary)
- OCP-1Z0-053-200题-186题-61
- 最小公倍数
- Xamarin Mono For Android 4.6.07004 完整离线安装破解版(C#开发Android、IOS工具)
- <MEMORY>Project Euler NO56
- OCP-1Z0-053-200题-185题-44
- hdu3853(概率DP求期望)
- 蓝桥杯-翻硬币
- C++ map的常用的使用方法整理