Objective-C 字典、可变字典
2015-11-27 19:47
519 查看
字典相当于c++ stl中的map
字典NSDictionary
可变字典 NSMutableDictionary
字典NSDictionary
#import <UIKit/UIKit.h> #import "AppDelegate.h" int main(int argc, char * argv[]) { // 从@符号创建字典 实际上就是键值对容器 NSDictionary *dict = @{@"name":@"zhangsan",@"sex":@"male"}; NSLog(@"%@",dict); // 根据键获取值 NSLog(@"%@",[dict objectForKey:@"name"]); // 从配置文件中读取 NSDictionary *dict1 = [NSDictionary dictionaryWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"data" ofType:@"plist" ]]; NSLog(@"%@",[dict1 objectForKey:@"name"]); NSLog(@"%@",[dict1 objectForKey:@"age"]); @autoreleasepool { return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); } }
可变字典 NSMutableDictionary
NSMutableDictionary *dict2 = [[NSMutableDictionary alloc]init]; // setObject 可以新增key 也可以修改已有key的值 [dict2 setObject:@"jinpangpang" forKey:@"name"]; [dict2 setObject:@"113" forKey:@"name"]; NSLog(@"%@",[dict2 objectForKey:@"name"]);
相关文章推荐
- object-c之scrollView图片轮播
- object-c之scrollView图片轮播
- Objective-C 数组、可变数组
- Objective-C新特性
- 转: [Objective-C]关联(objc_setAssociatedObject、objc_getAssociatedObject、objc_removeAssociatedObjects)
- 根据list<Object>中的某个字段排序
- jQuery.each(object, [callback])方法,用于处理json数组
- Objective—C实现UICollectionView中UICollectionViewCell的重排实现
- a different object with the same identifier value was already associated withthe session异常解决方案
- org.springframework.dao.InvalidDataAccessApiUsageException:The given object has a null identifi的解决方案
- org.springframework.dao.InvalidDataAccessApiUsageException:The given object has a null identifi的解决方案
- a different object with the same identifier value was already associated withthe session异常解决方案
- 转:Objective-C与JavaScript的交互
- Javascript] Object,(Date)
- 【原】objc_setAssociatedObject和objc_getAssociatedObject
- sumline text 正则匹配
- Object
- IOS开发基础Object-C(10)—OC内存管理(4)-autorelease使用
- Objective-C RunTime机制(1)
- 在ObjectARX中添加“块”