Reputation: 4235
i wonder if the way i programm is right way or not. can you help me?
@interface ViewController : UIViewController
{
UILabel *messageLabel;
}
@end
when i declare new object in .h and create in .m i have to use @property (nonatomic, retain) UILabel *messageLabel
? i saw few listings where when object are created by code @property
doesn't exist and few where does exist and i'm confused.
is it correct when i don't use @property (in example for UILabel
, UIImageView
, UIButton
) when i create objects by code?
Upvotes: 0
Views: 63
Reputation: 141
Your code is correct. @property
is used globally throughout your app, rather than being specific to your UIViewController
. If you are only planning on referring or changing the label/other component define it within the { }
otherwise @property
should be used
Upvotes: 1
Reputation: 10865
@property
is a key word useful to create setter/getter methods automatically for that field. If you don't need to access your label from outside your view controller you won't need to use @property
and your code is fine.
Upvotes: 2