Mr_Vlasov
Mr_Vlasov

Reputation: 537

What's really happen here?

 if ([self errorIsServerError:error] || [self errorIsBadRequest:error] || [self errorIsNetworkError:error]) {
    return YES;
}

The methods errorIsServerError:, errorIsBadRequest:, and errorIsNetworkError: all return the BOOL YES or NO.

But I don't understand the syntax. Is it:

if (YES || YES || YES) { return YES; }

?

Upvotes: 0

Views: 44

Answers (3)

soulshined
soulshined

Reputation: 10592

|| is the equivalent to saying 'or'. So your code is returning true if any of the values are true. This is what it's saying :

if ([self errorIsServerError:error] or [self errorIsBadRequest:error] or [self errorIsNetworkError:error]) 

If any of those are true then

{
    return YES;
}

Upvotes: 3

AstroCB
AstroCB

Reputation: 12367

Each of those returns YES if that particular categorization applies to the given error. If the error is a server or network error, or a bad request, the method will return YES.

You could look at it like this:

if ([self errorIsServerError:error]) {
  // The error is a server error
  return YES;
} else if ([self errorIsBadRequest:error]) {
  // The error is a bad request
  return YES;
} else if ([self errorIsNetworkError:error]) {
  // The error is a network error
  return YES;
}

In either case, it will return yes if the error is any of those types. It will also return YES if it is two or all of those types (|| is the logical (inclusive) "or" operator).

If it's none of the types, your method will continue until it hits another return statement.

Upvotes: 3

Carl Norum
Carl Norum

Reputation: 224864

It's not really clear what you're asking, but in general, you're probably expecting none of those errors to come through, meaning this if condition will evaluate false and your program can go on its way.

Upvotes: 2

Related Questions