mercredi 25 mai 2016

Is result of method called on nil object always behave the same in if statement

could you please confirm maybe with some words of wisdom if such lines of codes are equal:

a)

if (self.token && self.token.length > 0)
return YES;

b)

if ([self.token isValid])
 return YES;


- (BOOL)isValid
{
return self.length > 0;
}

As you can see in b) check for nil is removed and new method is introduced.

if self.token variable will be nil - do those two if statements will result in the same? I would assume yes, since [self.token isValid] will result in 0 I'm worried if b) example will always result the same as a)

Thanks for responses

Aucun commentaire:

Enregistrer un commentaire