On Wed, Apr 4, 2012 at 9:38 PM, Dave <d...@looktowindward.com> wrote:

> Hi,
>
> If it's a real error, this is what I do:
>
> - (id) initWithURL: (NSURL *) url
> {
> self = [super init];
> if (self == nil)
>        return nil;
>
> if (url == nil)
>        {
>        [self release];
>        return nil;
>        }
>
> return self;
> }
>
> or in this case, you could just do this:
>
> I think in the following you make a memory leak

> - (id) initWithURL: (NSURL *) url
> {
> if (url == nil)
>        return nil;
>
> self = [super init];
> if (self == nil)
>        return nil;
>
> return self;
> }
>
> The caller should check for a nil value returned from the init method.
>
> If it's a programming error, e.g. it should never happen, then it's
> probably best to log the error and abort the App.
>
> Hope this helps.
>
> All the Best
> Dave
>
>
> On 4 Apr 2012, at 12:38, Ariel Feinerman wrote:
>
>  Hi,
>>
>> I think the question was asked and answered but I cannot see a clearance
>> what is the right way to write init in the cases the arguments are nil or
>> wrong?
>> Returning a nil or raising an exception?
>>
>> - (id) initWithURL: (NSURL *) url {
>>
>>
>>  if ((self = [super init])) {
>>
>> if (!url) {
>>
>> // ?
>>
>> }
>>
>>  if (![url isFileURL]) {
>>
>> // ?
>>
>> }
>>
>> }
>>
>>  return self;
>>
>> }
>>
>> I can frequently see the following in init
>>
>> NSAssert(url, @"url may not be nil", );
>>
>> --
>> best regards
>> Ariel
>>
>> ______________________________**_________________
>>
>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>>
>> Please do not post admin requests or moderator comments to the list.
>> Contact the moderators at 
>> cocoa-dev-admins(at)lists.**apple.com<http://lists.apple.com>
>>
>> Help/Unsubscribe/Update your Subscription:
>> https://lists.apple.com/**mailman/options/cocoa-dev/**
>> dave%40looktowindward.com<https://lists.apple.com/mailman/options/cocoa-dev/dave%40looktowindward.com>
>>
>> This email sent to d...@looktowindward.com
>>
>
>


-- 
best regards
Ariel
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to