jarus
jarus

Reputation: 1873

How can we compare values in Objective-C like in PHP?

I am trying to compare the annotation title with title values to put different annotation image for different annotations. I tried to compare like in PHP:

if(title == "parking" || title = "car")
{
}

in Objective C I tried to do it like:

if([[annotation title] isEqualToString:@"Parking" || [annotation title] isEqualToString:@"Peace Hall" ] )
{
}

but it did not work. How can I accomplish this ?

Upvotes: 0

Views: 235

Answers (3)

puzzle
puzzle

Reputation: 6131

You need to send each isEqualToString: message separately, i.e.

if ([[annotation title] isEqualToString:@"Parking"] || [[annotation title] isEqualToString:@"Peace Hall"])
{
}

Upvotes: 0

Paul R
Paul R

Reputation: 212949

Change:

if ([[annotation title] isEqualToString:@"Parking" || [annotation title] isEqualToString:@"Peace Hall"])

to:

if ([[annotation title] isEqualToString:@"Parking"] || [[annotation title] isEqualToString:@"Peace Hall"])

Upvotes: 1

thomashw
thomashw

Reputation: 956

Looks like you just messed up the syntax. Try this:

if([[annotation title] isEqualToString:@"Parking"] || [[annotation title] isEqualToString:@"Peace Hall"] ) {
    /* Code */
}

Upvotes: 2

Related Questions