iphone - Dynamic VariableFromString in objective C -


i want dynamically create variable string in objective c.

like nsclassfromstring thats way. in want access variable.

any idea this?

if want dynamically access property of object, that's easy using key value coding.

if class kvc-compliant (most apple classes are), use valueforkey:, or valueforkeypath: method access property string.

consider example.

// shoe.h @interface shoe {     nsstring *brand;     nsnumber *size; }  @property (nonatomic, copy) nsstring *brand; @property (nonatomic, retain) nsnumber *size;  @end  // shoe.m @implementation   @synthesize brand, size;  @end 

let's create , initialize shoe object first.

shoe *someshoe = [[shoe alloc] init]; someshoe.brand = @"adidas"; someshoe.size = [nsnumber numberwithfloat:9.5]; 

considering example someshoe object, brand or size can accessed via string.

nsstring *brandname = [someshoe valueforkey:@"brand"]; 

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -