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

2013-01-30 Thread Mike Abdullah
On 30 Jan 2013, at 17:03, Quincey Morris wrote: > On Jan 30, 2013, at 00:42 , Charles Srstka wrote: > >> I *think* Xcode 4.2 was the one that introduced it, but my memory's not 100% >> on that. > > Weirdly, though, in Xcode 4.6 'instancetype' is not auto completing for me. > Is that a prob

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

2013-01-30 Thread Quincey Morris
On Jan 30, 2013, at 00:42 , Charles Srstka wrote: > I *think* Xcode 4.2 was the one that introduced it, but my memory's not 100% > on that. Weirdly, though, in Xcode 4.6 'instancetype' is not auto completing for me. Is that a problem others are experiencing? _

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

2013-01-30 Thread Greg Parker
On Jan 30, 2013, at 12:42 AM, Charles Srstka wrote: > On Jan 30, 2013, at 1:25 AM, Greg Parker wrote: >> Name the method `new...` instead of `create...`. Otherwise you do suffer an >> autorelease penalty with ARC. (`create...` is not one of the names that ARC >> assumes will return a retained r

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

2013-01-30 Thread Charles Srstka
On Jan 30, 2013, at 1:25 AM, Greg Parker wrote: > Name the method `new...` instead of `create...`. Otherwise you do suffer an > autorelease penalty with ARC. (`create...` is not one of the names that ARC > assumes will return a retained result.) Huh? I thought ARC generated objc_autoreleaseRet

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

2013-01-29 Thread Quincey Morris
On Jan 29, 2013, at 23:25 , Greg Parker wrote: > Name the method `new...` instead of `create...`. Otherwise you do suffer an > autorelease penalty with ARC. (`create...` is not one of the names that ARC > assumes will return a retained result.) Oops, I'm always getting that backwards. Need to

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

2013-01-29 Thread Greg Parker
On Jan 29, 2013, at 10:25 PM, Quincey Morris wrote: > 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

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

2013-01-29 Thread Quincey Morris
On Jan 29, 2013, at 20:51 , Ken Thomases 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). Howev

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

2013-01-29 Thread Charles Srstka
On Jan 29, 2013, at 10:51 PM, Ken Thomases wrote: > I disagree. I think Bob's construction is valid, if unconventional. It is > also valid-though-unconventional to release an object that you've +alloc'd > but not -init'd at the caller side. > > SomeClass* foo = [SomeClass alloc]; > if (someC

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

2013-01-29 Thread Ken Thomases
On Jan 29, 2013, at 3:22 AM, Quincey Morris wrote: > On Jan 29, 2013, at 00:51 , Bob Cromwell wrote: > >> if below code valid ? All sample codes I could find invoke "self = [super >> init]" first and then check the input parameter inside "if (self)" block. >> >> @implementaion Bla >> >> -

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

2013-01-29 Thread Quincey Morris
On Jan 29, 2013, at 09:07 , Jens Alfke wrote: > Actually this is fine, because free(NULL) is legal. A better example would be > a dealloc that calls CFRelease, because [for some reason] CFRelease does > crash if passed NULL. Yes, no one is ever going to hire me for my deep Unix knowledge. > I

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

2013-01-29 Thread Jens Alfke
On Jan 29, 2013, at 1:22 AM, Quincey Morris wrote: > ** Here's an example that will crash with an early return: > > if (self) { > if (foo == nil) > return nil; > _foo = foo; > _bar = malloc (100); > . > } > ….. > - (void) dealloc { >free (_bar); >

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

2013-01-29 Thread Quincey Morris
On Jan 29, 2013, at 00:51 , Bob Cromwell wrote: > if below code valid ? All sample codes I could find invoke "self = [super > init]" first and then check the input parameter inside "if (self)" block. > > @implementaion Bla > > - (id)initWithFoo:(NSString *)foo > { >if (foo == nil) { >

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

2013-01-29 Thread Bob Cromwell
Hi All, if below code valid ? All sample codes I could find invoke "self = [super init]" first and then check the input parameter inside "if (self)" block. @implementaion Bla - (id)initWithFoo:(NSString *)foo { if (foo == nil) { return nil; } self = [super init]; if