开发者

Is it possible to access the member variable of object

I created a subclass AOBject from NSObject

@interface AObject : NSObject {
    NSinteger m;
    NSInteger n;
}


-(void) setM:(NSInteger)v ;
 -(NSInteger ) getM ;
-(void) setN:(NSInteger)v ;
 -(NSInteger ) getN ; 

To access m,n ,I can use [myAObject getM] or [m开发者_开发问答yAObject getN]

Is it possible to access m,n using tag or any other way that I can access all member variables of an object in a queue?

Welcome any comment.

Thanks

interdev


You can't access integers using tag or anything; you have to go through the setters and getters you've made.

If you wanted to access each of these member variables, you could use NSNumber instead of NSInteger, and explicitly create an array to do hold these values. To do that, declare a localVariables array, and initialize it in your constructor, like so:

-(id) init {
    if (self = [super init]) {

        // initialize and set values for m and n
        NSArray *array = [[NSArray alloc] initWithObjects:self.m, self.n, nil];
        self.localVariables = array;
        [array release];
    }
    return self;
} 

Then you can iterate through this to access all local variables.

By the way, you can take care of setters and getters by adding

@property NSInteger m;
@property NSInteger n;

to your header file, and

@synthesize m,n;

to your implementation file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜