Reputation: 77631
I have a couple of classes that I set up properties in.
e.g. a class called MyDetailCell
that subclassed UITableViewCell
.
In it I had a property something like...
@property SomeClass *someValue;
Initially I was using it and storing it within the setter function...
- (void)setSomeValue:(SomeClass*)someValue
{
_somValue = someValue;
//do something with the _someValue object like changing text or something...
}
Anyway, I decided that I didn't actually need to store the value that was sent in so I was just doing this...
- (void)setSomeValue:(SomeClass*)someValue
{
//do something with the _someValue object like changing text or something...
}
And then I changed to where I was just passing the setter forward to a subview. Like this...
- (void)setSomeValue:(SomeClass*)someValue
{
self.someSubView.someValue = someValue;
}
So now I'm not sure what to use. I'm not actually saving the property at all now so I guess I don't really need it. I don't need to access it to get the value either I just need to set it.
At the moment I've left the property in there as it is.
Upvotes: 0
Views: 58
Reputation:
Is that OK?
No.
Is it bad practice?
Yes.
Should I change it for a just a setter method instead? What are the benefits of doing that?
I don't see what you mean by this. You wrote 'just a setter method' and you also did some processing in the setter method, which is fine, but you did other things wrong. One is that you don't retain a non-delegate object - you should. You don't provide a getter - that's also a broken concept. There can be readonly and readwrite properties, but not write only properties.
Upvotes: 1