项目作者: shaojiankui

项目描述 :
非常有助于IOS字典读写的轻量级扩展,Very useful safe accessors for NSDictionary,a lightweight NSDictionary access category
高级语言: Objective-C
项目地址: git://github.com/shaojiankui/NSDictionary-SafeAccess.git
创建时间: 2015-04-25T11:40:43Z
项目社区:https://github.com/shaojiankui/NSDictionary-SafeAccess

开源协议:MIT License

下载


NSDictionary-SafeAccess

非常有助于IOS字典读写的轻量级扩展,Very useful safe accessors for NSDictionary,a lightweight NSDictionary access category

比如网络请求回来的JSON解析成字典后,数据的读取常常因为NULL而程序崩溃,有了SafeAccess

妈妈再也不用担心NULL啦

使用方法

读取 getter

  1. NSDictionary *responseObject = /.......
  2. NSDictionary *dic = [responseObject dictionaryForKey:@"object"];
  3. NSArray *array = [responseObject arrayForKey:@"array"];
  4. NSString *string = [responseObject stringForKey:@"string"];
  5. long long date = [responseObject longLongForKey:@"date"];
  6. NSNumber *number = [responseObject numberForKey:@"number"];
  7. NSInteger count = [responseObject integerForKey:@"count"];
  8. BOOL b = [responseObject boolForKey:@"count"];
  9. CGPoint point = [responseObject pointForKey:@"point"];
  10. CGFloat f = [responseObject CGFloatForKey:@"float"];
  11. CGRect rect = [responseObject rectForKey:@"rect"];
  12. CGSize size = [responseObject sizeForKey:@"size"];

写入 setter

  1. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  2. [dict setObj:@"334" forKey:@"obj"];
  3. [dict setString:@"string" forKey:@"str"];
  4. [dict setBool:YES forKey:@"b"];
  5. [dict setInt:1 forKey:@"intvalue"];
  6. [dict setCGFloat:1.1 forKey:@"float"];
  7. [dict setPoint:CGPointMake(1, 1) forKey:@"point"];
  8. [dict setSize:CGSizeMake(111, 111) forKey:@"size"];
  9. [dict setRect:CGRectMake(0, 0, 0, 0) forKey:@"rect"];

更多Catgories

https://github.com/shaojiankui/IOS-Categories