Reputation: 29886
I set a value in one class and then I want to retrieve that value without creating an object for it.
When I use classname.variableName from another class(which I declare the variableName as property and synthesize it) I get an unknown class method error.
How can I just set an NSString in one class and just reference it from another. I dot want to create an object.
Upvotes: 0
Views: 1354
Reputation: 491
One can implement it by passing the value to next class under navigationController using pushviewController. Or it can be implemented also by taking variable in delegate class and use it in anyclass using delegate's instance.
Upvotes: 0
Reputation: 9810
make sure you are using #import "ClassThatAlreadyExists.h"
in your SecondClassThatAlreadyExists. Also, following the above example, to get the string variable you would use this in SecondClassThatAlreadyExists:
//assuming you haven't declared and initialized the object yet.
ClassThatAlreadyExists *objectThatAlreadyExists = [[ClassThatAlreadyExists alloc] init];
objectThatAlreadyExists.variableName = @"hey im the sample string that is being set";
Upvotes: 2
Reputation: 4846
Perhaps you are setting it up incorrectly. Here is how you could set it up:
@interface ClassThatAlreadyExists : NSObject {
// Other ivars
NSString *variableName;
}
// Other @property's
@property (nonatomic, copy) NSString *variableName;
@end
@implementation ClassThatAlreadyExists
// other @synthesize's
@synthesize variableName;
// rest of implementation
@end
Upvotes: 3