I have a UIImageView based class (lets call it classA) that uses a classB and was declared something like that…
@interface classA : UIImageView {
@public classB *mylabel;
}
@property (nonatomic, retain) classB *mylabel;
... @synthesize myLabel was put on its .m
class B was declared something like
@interface classB : UILabel {
@public UILabel *myCustomlabel;
}
@property (nonatomic, retain) classB *myCustomlabel;
... @synthesize myCustomlabel was put on its .m
now I am on the main code. I create an object like this
classA *myObject = [[classA alloc] init];
myObject.myLabel.myCustomLabel.text = @"Hi there";
// this last line fails. It says there's not myCustomLabel structure on myLabel!!!
why is this happening if everything is public?
thanks
I am not sure if it is the typo or not but there is mistake between “l” and “L” in your code. It is likely that this creates your problem because you mess up between “l” and “L”
So, I guess, for your code, when you call
myObject.myLabel, it uses the get of the @property and @synthesize, then the next myCustomLabel, it doesn’t find any (variable, property + synthesize) like that so it complainsGenerally, if you already declare @property + @synthesize, you don’t need and should’n have public variable. The @property generates public getter and setter method already