Implied use of Properties
Implied use of Properties
- Subject: Implied use of Properties
- From: Dave <email@hidden>
- Date: Fri, 2 Apr 2010 21:48:45 +0100
Hi All,
I came across this code and was wondering if this is normal practice
and/or considered good coding style.
Given two classes ClassX and ClassY:
@interface ClassX
{
ClassY mClassY;
}
@property (nonatomic,retain,readonly) ClassY* mClassY
@end
@interface ClassY
{
int mClassYValue;
}
@property (nonatomic,retain,readonly) ClassY* mClassY
@end
@implementation ClassX
-(ClassY*) mClassY
{
if (mClassY == nil)
{
mClassY [[ClassY alloc] initWithData:someData]:
}
return mClassY;
}
Then later in another method of ClassX, I found the following code:
self.mClassY. mClassYValue = someValue;
Before this statement is executed, self. mClassY is nil. When it is
executed it causes the "mClassY" method to be called which allocates
the Class and sets the Variable.
Is this normal? Looking at the code it seems hard to see what is
going on, Surely it would be better practice to have an init method
that does this? e.g.
self.mClassY = [[alloc] initWithData: initWithData:someData]
Just trying to figure out the best approach for something like this.
Thanks in Advance
Dave
@end
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden