• 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: verify input parameter of init method and return nil before invoke [super init]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: verify input parameter of init method and return nil before invoke [super init]


  • Subject: Re: verify input parameter of init method and return nil before invoke [super init]
  • From: Quincey Morris <email@hidden>
  • Date: Tue, 29 Jan 2013 22:25:23 -0800

On Jan 29, 2013, at 20:51 , Ken Thomases <email@hidden> wrote:

> Bob's construction is just as valid as the above because it's essentially doing the same thing.

The same thing, so it doesn't really adduce any further evidence (unless you know of a documented API contract that covers this situation).

However, it occurs to me there's a better solution. Since we're talking about ARC, this pattern:

+ (id) createBlaWithFoo: (NSString*) foo // or the return type can be Bla* if you want
{
	if (!foo)
		return nil;
	else
		return [[Bla alloc] initWithFoo: foo];
}

is superior all round. It has no autorelease penalty, may reduce the number of keystrokes at the call site, and is impervious to the particular exploding dealloc problem we've been discussing.

_______________________________________________

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: verify input parameter of init method and return nil before invoke [super init]
      • From: Greg Parker <email@hidden>
References: 
 >verify input parameter of init method and return nil before invoke [super init] (From: Bob Cromwell <email@hidden>)
 >Re: verify input parameter of init method and return nil before invoke [super init] (From: Quincey Morris <email@hidden>)
 >Re: verify input parameter of init method and return nil before invoke [super init] (From: Ken Thomases <email@hidden>)

  • Prev by Date: Re: verify input parameter of init method and return nil before invoke [super init]
  • Next by Date: Re: verify input parameter of init method and return nil before invoke [super init]
  • Previous by thread: Re: verify input parameter of init method and return nil before invoke [super init]
  • Next by thread: Re: verify input parameter of init method and return nil before invoke [super init]
  • Index(es):
    • Date
    • Thread