Coder Social home page Coder Social logo

nsdictionary-extension's Introduction

NSDictionary-Extension

Extension for NSDictionary to do more with NSDictionary

No more nil value

objectForKey: withHolder: This Extension made to provide method to retrieve objectForKey: by passing Holder to method objectForKey: withHolder: in case that the key you want does not exits this method will return Holder instead of nil value Note

  • The returned object will be forced to be the same class as Holder
  • Holder must be object based variable
    NSDictionary *objects = @{@"x":@"xxx",@"y":@"yyy"};
    NSString *output1 = [objects objectForKey:@"z"];
    NSLog(@"Output 1: %@",output1); //Output 1: (null)
    NSString *output2 = [objects objectForKey:@"z" withHolder:@"zzz"];
    NSLog(@"Output 2: %@",output2); //Output 2: zzzz

Easy way to turn NSDictionary to JSON string

- (NSString *)toJSONString; Pretty Print JSON from NSDictionary

    NSDictionary *objects = @{@"x":@"xxx",@"y":@"yyy"};
    NSString *jsonString = [objects toJSONString];

Output

JSON: {
  "x" : "xxx",
  "y" : "yyy"
}

nsdictionary-extension's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.