How can we compare values in Objective-C like in PHP?
I am trying to compare the annotation title with 开发者_如何学JAVAtitle 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 ?
Looks like you just messed up the syntax. Try this:
if([[annotation title] isEqualToString:@"Parking"] || [[annotation title] isEqualToString:@"Peace Hall"] ) {
/* Code */
}
Change:
if ([[annotation title] isEqualToString:@"Parking" || [annotation title] isEqualToString:@"Peace Hall"])
to:
if ([[annotation title] isEqualToString:@"Parking"] || [[annotation title] isEqualToString:@"Peace Hall"])
You need to send each isEqualToString:
message separately, i.e.
if ([[annotation title] isEqualToString:@"Parking"] || [[annotation title] isEqualToString:@"Peace Hall"])
{
}
精彩评论