NSDictionary+Accessors 1.0.0

NSDictionary+Accessors 1.0.0

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Dec 2014

Maintained by Unclaimed.


Downloads

Total34,270
Week0
Month0

Installs

Apps662
Pod Tries2
Test Targets28
powered by Segment

GitHub

Stars60
Watchers1
Forks9
Issues0
Contributors1
Pull Requests1

Code

Files2
LOCLines of Code 172


  • By
  • Allen Hsu

NSDictionary-Accessors

Type safe accessors for NSDictionary, better used with dictionary parsed from JSON.

Before:

id value = nil;
value = [dictionary objectForKey:@"id"];
if ([value isKindOfClass:[NSNumber class]]) {
    model.identifier = [value unsignedLongLongValue];
}
value = [dictionary objectForKey:@"title"];
if ([value isKindOfClass:[NSString class]]) {
    model.title = value;
}
value = [dictionary objectForKey:@"content"];
if ([value isKindOfClass:[NSString class]]) {
    model.content = value;
}

Problems:

  • Boilerplate code
  • 64bit ids will be returned as string instead of number in some api
  • Libs like RestKit even lighter JSONModel are still heavy for simple apps sometimes

What you need is just AFNetworking + NSDictionary+Accessors

After:

model.identifier = [dictionary unsignedLongLongForKey:@"id"];
model.title = [dictionary stringForKey:@"title"];
model.content = [dictionary stringForKey:@"content"];