Jack Humphries
Jack Humphries

Reputation: 13267

Where to place ||

I know that this is a really simple question, but where should I place the || below if I want to check for both CAF and AAC? Thanks!

if ([[file pathExtension] isEqualToString:@"caf"])

Upvotes: 2

Views: 170

Answers (4)

JonasG
JonasG

Reputation: 9324

|| means 'or' in Objective c. So this if (a == 1 || a == 2) means if a is equal to 1 OR a is equal to 2. So:

== equal

&& and

|| or

Upvotes: 0

gamozzii
gamozzii

Reputation: 3921

if ([[file pathExtension] isEqualToString:@"caf"] ||
    [[file pathExtension] isEqualToString:@"aac"] )

Note - this is a literal comparison so it is not case insensitive - if you want to do a case insensitive comparison:

if ([[file pathExtension] compare:@"caf" options:NSCaseInsensitiveSearch] == NSOrderedSame || 
    [[file pathExtension] compare:@"aac" options:NSCaseInsensitiveSearch] == NSOrderedSame)

Upvotes: 4

sidyll
sidyll

Reputation: 59287

You have to test it twice:

if ([[file pathExtension] isEqualToString:@"caf"] ||
    [[file pathExtension] isEqualToString:@"aac"])

Or, avoid some repetition by doing it like:

NSString *ext = [file pathExtension];
if ([ext isEqualToString:@"caf"] ||
    [ext isEqualToString:@"aac"])

Upvotes: 3

Tim Dean
Tim Dean

Reputation: 8292

if ([[file pathExtension] isEqualToString:@"caf"] || [[file pathExtension] isEqualToString:@"aac"])

Upvotes: 5

Related Questions