views:

95

answers:

4

I am trying to compare the following values:

 gType = [[UILabel alloc]init];
 if (gType = [NSString string:@"BUSINESS"]) {

I get a warning 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,

+1  A: 

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

Azeem.Butt
+1  A: 

You're looking for:

if ([someString isEqual:@"Something else"]) { ... }
Dave DeLong
+1  A: 

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"])
bpapa
thx for all of the answers...I tried this one and it worked.On to the next glitch
Wes
A: 

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.

Jasarien