2008年9月13日 星期六

key value coding

ex:
.h檔

@interface AppController : NSObject {

int test;

}

@end


.m檔

// set test

[self setValue:[NSNumber numberWithInt:5]

forKey:@"test"];

// get test

NSNumber *n=[self valueForKey:@"test"];


// is called when valueForKey is called

-(int)test

{

NSLog(@"test is returning %d", fido);

return fido;

}


// is called when setValue is called

-(void)setTest:(int)x

{

NSLog(@"setTest is called with %d", x);

fido=x;

}



沒有留言: