Reputation: 547
I'd like to check that I'm not causing myself any issues with the way I'm creating a custom View, which is a subclass of UIVIEW and I'm adding a UISlider as a subview.
My understanding is that Properties are public objects and defined in the .h using @roperty, instance variables etc are defined in the .m file. Based on this simplistic logic is the way I'm defining the UISlider correct/good, it works and feels correct but will this cause any memory issues and is it the correct way of doing things? I having nothing defined in the .h file and the following in the .m file?
#import "myWidgetView.h"
@implementation myWidgetView {
UISlider *eraseSlider;
}
- (id)initWithCoder:(NSCoder *)aDecoder {
if (self = [super initWithCoder:aDecoder])
{
eraseSlider = [[UISlider alloc] init];
[self addSubview:eraseSlider];
}
return self;
}
Upvotes: 0
Views: 41
Reputation: 119031
Properties aren't only public, you can have private ones too. Their usage is a bit personal preference. Personally, I don't use any plain instance variables, I use properties for everything. I know other people don't work in the same way.
Instance variables aren't only private. Public / private is controlled by what's in the .h / .m files really. Both properties and instance variables can be defined in both.
The benefit of properties is that they describe your intentions in terms of memory and thread management and access control. Plain instance variables tell you nothing. Properties also generate accessor methods based on your stated intentions.
What you have (as a very minimal example) is fine. Just understand the features offered by each of the constructs you're using and decide how you want to structure your classes.
Upvotes: 1