Latest 0.0.1
License Apache
Platforms osx , ios , tvos , watchos , requires ARC

A simple XPath like structure to query through NSDictionary in Objective-C. Go to OCGXPathDictionary-Swift for the Swift version.


Let’s say we have an NSDictionary representation of the following json structure.

  "Level1" : {
    "Level2" : {
      "Level3" : {
        "Level4" : "I want this"

Traditionally, what we would do to get the value of Level4 is:

NSDictionary *level1 = dictionary[@"Level1"];
if (level1 && ![level1[@"Level2"] isKindOfClass:[NSNull class]]) {
    NSDictionary *level2 = level1[@"Level2"];
    if (level2 && ![level2[@"Level3"] isKindOfClass:[NSNull class]]) {
        NSDictionary *level3 = level2[@"Level3"];
        if (level3 && ![level3[@"Level4"] isKindOfClass:[NSNull class]]) {
            NSString *level4Value = level3[@"Level4"];

Yet, this is an ugly and annoying piece of code to write. OCGXPathDictionary helps you to parse your dictionary with one line of code :)


    pod 'OCGXPathDictionary'


NSString *myValue = [dictionary parseDictionaryWithComponents:@"Level1", @"Level2", @"Level3", @"Level4", nil];


NSString *myValue = [dictionary parseDictionaryWithXPath:@"Level1/Level2/Level3/Level4"];


NSString *myValue = [dictionary parseDictionaryWithObjects:@[@"Level1", @"Level2", @"Level3", @"Level4"]];

Latest podspec

    "name": "OCGXPathDictionary",
    "version": "0.0.1",
    "summary": "A simple XPath like structure to query through NSDictionary",
    "description": "A simple XPath like structure to quert through NSDictionary in Objective-C.",
    "homepage": "",
    "license": {
        "type": "Apache",
        "file": "LICENSE"
    "authors": "Oguzhan Gungor",
    "source": {
        "git": "",
        "tag": "0.0.1"
    "source_files": [
    "requires_arc": true,
    "platforms": {
        "osx": null,
        "ios": null,
        "tvos": null,
        "watchos": null

Pin It on Pinterest

Share This