Don't have the right syntax when comparing strings in iPhone
I am trying to compare the following values:
gType = [[UILabel alloc]init];
if (gType = [NSString string:@"BUSINESS"]) {
I get a warni开发者_Python百科ng that 'NSString' may not respond to '+string:'
I am unsure what is wrong. gType is a value that I populate from a db query. Other text values from the same query show up fine in a UITableView, so I am pretty confident I have created it properly.
thx,
Your code is calling the "String" class method on the NSString class. This doesn't accept any arguments, which is your problem here.
The correct way to write your code would be something like:
if ([gType.text isEqualToString:@"BUSINESS"])
For starters, = is the assignment operator in C and does not compare anything. Secondly, even if you were using a comparison operator there, you'd be comparing pointer addresses, not the textual contents of the objects.
Read this
You're looking for:
if ([someString isEqual:@"Something else"]) { ... }
As NSD said, you have a few fundamental problems with your code there.
If you want to compare strings in Cocoa Touch, you can use the -isEqualToString:
method on NSString.
精彩评论