How do I call a variable from another class?

Posted by squeezemylime on Stack Overflow See other posts from Stack Overflow or by squeezemylime
Published on 2010-06-05T22:56:52Z Indexed on 2010/06/05 23:02 UTC
Read the original article Hit count: 151

Filed under:
|
|
|

I have a class called 'Constants' that I am storing a String variable in. This class contains a few global variables used in my app.

I want to be able to reference this class and call the variable (called profileId) in other Views of my app.

I looked around and found a few examples, but am not sure how to do this. Currently my setup is:

Constants.h

@interface Constants : UIViewController {
NSString *profileId;
}

@property (nonatomic, retain) NSString *profileId;

@end

Constants.m

#import "Constants.h"

@implementation Constants

@synthesize profileId;

- (void)dealloc {
[profileId release];

[super dealloc];
}

And I am trying to call the variable profileId in a new View via this way:

NewView.h file

@class Constants;

NewView.m file

NSLog(@"ProfileId is:", [myConstants profileId]);

Is there something I'm missing? It is coming up null, even though I am properly storing a value in it in another function via this way:

Constants *Constant;
    Constant = [[Constants alloc] init];
    Constant.profileId = userId;

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c