• 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
Re: Implied use of Properties
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Implied use of Properties


  • Subject: Re: Implied use of Properties
  • From: Klaus Backert <email@hidden>
  • Date: Tue, 6 Apr 2010 23:39:56 +0200


On 6 Apr 2010, at 16:19, Dave wrote:

Also as far as I can see, there are a couple of draw-backs to doing it this way. In the example:

-(ClassY*) mClassY
{
if (mClassY == nil)
	{
	mClassY = [[ClassY alloc] initWithData:someData]:
	}
return mClassY;
}

The reasons I don't like this are:

1. "someData" is hardwired and it's impossible to pass a parameter to "mClassY" since it's a getter.

Yes, and in the OpenGL example a gave, there is indeed something hardwired: the attributes of the pixel format the OpenGL context is built upon -- which is no problem for this kind of application.


2. If either the alloc or initWithData methods fail there is no way to pass the error back to the caller except by passing nil as the Class Selector. And if this were done in a statement like:

self.mClassY. mClassYValue = someValue;

I'm not sure what would happen but it wouldn't be good news!

After getting the OpenGL context property, I always have an assertion in the debug configuration (see below). And I almost never concatenate several invocations of methods, including properties. For debugging purposes I have a lot of assertions in between (may be, I'm a little bit paranoid, but, well, what would you expect from a mathematician ;-).


@interface MyCustomView : NSView
{
@private
	NSOpenGLContext * mContext;
}
...
@property (readonly, retain) NSOpenGLContext *myContext;
...
@end

@implementation MyCustomView
...
@dynamic myContext;
...
- (NSOpenGLContext *) myContext
{
if (mContext == nil)
{
mContext = [[NSOpenGLContext alloc] initWithFormat: self.myPixelFormat shareContext: nil];
}
return mContext;
}
...
- (void)mySomethingOne
{
NSOpenGLContext *theContext = self. myContext;
MY_ASSERT(theContext != nil);
...
}
- (void)mySomethingTwo
{
NSOpenGLContext *theContext = self. myContext;
MY_ASSERT(theContext != nil);
...
}
@end


There is, of course, a release (and setting to nil) in dealloc, in order to balance the retain by alloc-init.

Whatever is called first, mySomethingOne or mySomethingTwo, the context is created at that point during the execution.

-(ClassY*) SetmClassY (ClassY* theClassY)


This should be

- (void)setmClassY: (ClassY *)theClassY

regards
Klaus

_______________________________________________

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


References: 
 >Implied use of Properties (From: Dave <email@hidden>)
 >Re: Implied use of Properties (From: Klaus Backert <email@hidden>)
 >Re: Implied use of Properties (From: Dave <email@hidden>)

  • Prev by Date: Re: Alternative Location of Cocoa ID3 Framework??
  • Next by Date: Re: NSImageView Will Not Alias Images
  • Previous by thread: Re: Implied use of Properties
  • Next by thread: C typedef for NS ptrs?
  • Index(es):
    • Date
    • Thread