Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You Can Implement it as :</p> <p>@implementation MyObject</p> <pre><code>-(id) initFromDictionary:(NSDictionary*)dict { self = [super init]; if (self) { a = ([dict objectForKey: @"a"]) ? [[dict objectForKey: @"a"] intValue] : 0; b = ([dict objectForKey: @"b"]) ? [[dict objectForKey: @"b"] intValue] : 0; c = ([dict objectForKey: @"c"]) ? [[dict objectForKey: @"c"] intValue] : 0; </code></pre> <blockquote> <p>// Here you can replace 0 with nil in case if variable a , b , c are object type i.e. (id) type or You can use default value here as per your convenience so that you can easily track it if it is partially or fully Loaded</p> </blockquote> <pre><code> if ((a == 0) || (b == 0) || (c == 0)) { NSLog(@"object is Partially loaded with values a : %d , b : %d , c : %d", a,b,c); }else{ NSLog(@"object is Completely loaded with values a : %d , b : %d , c : %d", a,b,c); } } return self; } @end </code></pre> <p>Or</p> <pre><code>@implementation MyObject -(id) initFromDictionary:(NSDictionary*)dict { self = [super init]; if (self) { NSArray *keys = [dict AllKeys]; for(NSString * key in keys) { [self setValueToItsVariableForKey:key fromDictionary: dict]; } } return self; } - (void)setValueToItsVariableForKey:(NSString *)key fromDictionary: (NSDictionary *)dict { switch ([key intValue]) { case : a a = [[dict objectForKey: key] intValue]; break; case : b b = [[dict objectForKey: key] intValue]; break; case : c c = [[dict objectForKey: key] intValue]; break; } } @end </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload