• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Implied use of Properties
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Implied use of Properties
      • From: Klaus Backert <email@hidden>
    • Re: Implied use of Properties
      • From: Quincey Morris <email@hidden>
  • Prev by Date: Re: How to save and restore NSScrollView scroll position?
  • Next by Date: Re: MutableArray losing contents
  • Previous by thread: Re: How to save and restore NSScrollView scroll position?
  • Next by thread: Re: Implied use of Properties
  • Index(es):
    • Date
    • Thread