I have below code
NSString *firstName = @"1.6.1";
NSString *secondName = @"1.6.1";
if (!(firstName==secondName)) {
NSLog(@"lock the app");
} else {
NSLog(@"do not lock the app");
}
if (!([firstName isEqualToString:secondName])) {
NSLog(@"lock the app");
} else {
NSLog(@"do not lock the app");
}
Output I am getting is
do not lock the app
do not lock the app
However when I use actual values for firstName
& secondName
, I get output as
lock the app
do not lock the app
Below are details of firstName
& secondName
// this is coming from server
firstName = [[NSUserDefaults standardUserDefaults] stringForKey:@"iPhoneAppVersion"];
// this is coming from app version from iPhone
secondName = [self appNameAndVersionNumberDisplayString];
- (NSString *)appNameAndVersionNumberDisplayString {
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
NSString *appDisplayName = [infoDictionary objectForKey:@"CFBundleDisplayName"];
NSString *majorVersion = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
NSString *minorVersion = [infoDictionary objectForKey:@"CFBundleVersion"];
return [NSString stringWithFormat:@"%@",
minorVersion];
}
If I print firstName
& secondName
, I get values as 1.6.1
, 1.6.1
respectively.
Any idea why there are two different outputs when using equals?