开发者

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

开发者 https://www.devze.com 2023-03-13 08:07 出处:网络
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:

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"])
{
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号