objective c - how to read values from custom class -


i have class person.

person.h

#import <foundation/foundation.h>  @interface person : nsobject{     nsstring *name;     nsstring *screen_name; } @property (nonatomic, retain) nsstring *name; @property (nonatomic, retain) nsstring *screen_name;  @end 

person.m

#import "person.h"  @implementation person  @synthesize text,screen_name;  @end 

i have nsarray object, values, such text, screen_name , etc.

i do:

person * person = object; ( object nsarray) 

i values, this: person.name, person.screen_name

object :

{         "screen_name" = "mika_alcala";         "text" ="";         "time_zone" = "eastern time (us & canada)";         "url" = "<null>";         "utc_offset" = "-14400";         "verified" = 0; }; 

ok, first don't need define ivars , don't need synthesize xcode 4.5+ (iirc).

so should like...

person.h

#import <foundation/foundation.h>  @interface person : nsobject  @property (nonatomic, retain) nsstring *name; @property (nonatomic, retain) nsstring *screen_name;  @end 

person.m

#import "person.h"  @implementation person  @end 

for actual question i'm not sure you're asking. i'll have ask further...

edit show how create array

first off...

object : {         "screen_name" = "mika_alcala";         "text" ="";         "time_zone" = "eastern time (us & canada)";         "url" = "<null>";         "utc_offset" = "-14400";         "verified" = 0; }; 

this object nsdictionary not , nsarray.

there 2 ways of doing this...

  1. create blank person object , set values dictionary.

    person *person = [[person alloc] init]; person.name = object[@"screen_name"]; person.screen_name = object[@"screen_name"]; 
  2. add custom init method person object.

person.h

#import <foundation/foundation.h>  @interface person : nsobject  @property (nonatomic, retain) nsstring *name; @property (nonatomic, retain) nsstring *screen_name;  - (id)initwithdictionary:(nsdictionary *)dictionary;  @end 

person.m

#import "person.h"  @implementation person  - (id)initwithdictionary:(nsdictionary *)dictionary {     self = [super init];     if (self) {         _name = dictionary[@"screen_name"];         _screen_name = dictionary[@"screen_name"];     }     return self; }  @end 

then can do...

person *person = [[person alloc] initwithdictionary:object]; 

whichever method follow able hold of person.name , person.screen_name.


Comments

Popular posts from this blog

php - get table cell data from and place a copy in another table -

javascript - Mootools wait with Fx.Morph start -

php - Navigate throught databse rows -