Latest 1.1.0
Homepage https://github.com/Naituw/NSDictionary-Accessors
License MIT
Frameworks Foundation
Authors

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"];

Latest podspec

{
    "name": "NSDictionary+Accessors-BothPlatform",
    "version": "1.1.0",
    "summary": "Type safe accessors for NSDictionary, better used with dictionary parsed from JSON.",
    "homepage": "https://github.com/Naituw/NSDictionary-Accessors",
    "license": "MIT",
    "authors": {
        "Allen Hsu": "[email protected]"
    },
    "source": {
        "git": "https://github.com/Naituw/NSDictionary-Accessors.git",
        "tag": "1.1.0"
    },
    "frameworks": "Foundation",
    "source_files": "*.{h,m}",
    "requires_arc": true
}

Pin It on Pinterest

Share This