• 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: Method not seeing array as array
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Method not seeing array as array


  • Subject: Re: Method not seeing array as array
  • From: Shawn Erickson <email@hidden>
  • Date: Wed, 2 Feb 2005 17:43:30 -0800


On Feb 2, 2005, at 5:24 PM, Andrew Farmer wrote:

On 2 Feb 2005, at 13:08, Marco Scheurer wrote:
While not harmful, and probably good style (except for the the 'if(!self) return nil' line)

Is there something wrong with
if(!self) return nil;
other than its being a shorthand for
if(self == nil) return nil;
?

In reality no... it more clearly conveys your intent to test against nil since nil explicitly implies no object.


(following written in mail rapidly...)

I personally prefer the following pattern for simple cases...

-(id)init
{
	if ((self = [super init]) != nil) {
		...blah...
	}

	return self;
}

...or the following for more complex cases (assumes dealloc will clean stuff as needed)...

-(id)init
{
	bool failed = NO;

	if ((self = [super init]) == nil) {
		return nil;
	}

	for(;;) {
		..blah..
		if (someThingFailed) {
			failed = YES;
			break;
		}

		..blah..
		if (someThingElseFailed) {
			failed = YES;
			break;
		}
	}

	if (failed) {
		[self release];
		self = nil;
	}

	return self;
}

...or for those that don't fear the goto...

-(id)init
{
	if ((self = [super init]) == nil) {
		return nil;
	}

	..blah..
	if (someThingFailed) goto initFailed;

	..blah..
	if (someThingElseFailed) goto initFailed;

	return self;

initFailed:
	[self release];
	return nil;
}

-Shawn

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Method not seeing array as array
      • From: Will Mason <email@hidden>
    • Re: Method not seeing array as array
      • From: Andrew Farmer <email@hidden>
References: 
 >Method not seeing array as array (From: Michael Swan <email@hidden>)
 >Re: Method not seeing array as array (From: Andrew Farmer <email@hidden>)
 >Re: Method not seeing array as array (From: Marco Scheurer <email@hidden>)
 >Re: Method not seeing array as array (From: Andrew Farmer <email@hidden>)

  • Prev by Date: Re: NSDocument setFileName - File Must Exist?
  • Next by Date: Re: Beginner Questions
  • Previous by thread: Re: Method not seeing array as array
  • Next by thread: Re: Method not seeing array as array
  • Index(es):
    • Date
    • Thread