i am facing a weird problem i am simply comparing two string values and doing something if it matches .. i have created a Python script server from where i get one value and the other value is local string variable. i am able to retrive the proper value fromt the server but when comparing it does not enter the loop..
This is my code in my client to compare the values
-(void)messageReceived:(NSString *)message {
[_messages addObject:message];
NSLog(@"the received message is %@",message);
if (message == @"1")
NSLog(@"the user is online");
else if (message == @"0") {
UIAlertView *alert;
alert = [[UIAlertView alloc]initWithTitle:@"Message" message:@"The selected user is not online !" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles: nil];
[alert show];
}
}
Here is a log that that i get showing the proper values
2012-02-25 21:44:35.376 iMessenger[2001:207] server said: 1
2012-02-25 21:44:35.377 iMessenger[2001:207] the received message is 1
can someone suggest me what is wrong .. Thanks
Don’t use == to compare strings. Use
[message isEqualToString:@"1"]instead.