Accessing unknown class method when trying to use getter
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.
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
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";
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.
精彩评论