Compare strings on iPhone fails?
I'm trying to compare two strings with each other on the iphone, but the IF statement is always false. Here's my code:
NSLog([[UIDevice currentDevice]uniqueId开发者_运维问答entifier]);
if ([[[UIDevice currentDevice]uniqueIdentifier] compare:[[NSUserDefaults standardUserDefaults] valueForKey:@"id"]] == NSOrderedSame) {
//OK
NSLog("Do stuff if equal");
} else {
// Not OK
NSLog("Do stuff if not equal");
}
The output is always
*** UDID *** (<- my device's UDID)
Do stuff if not equal
What am I doing wrong?
Thanks! Yvan
Try using stringForKey:
instead of valueForKey:
, and isEqualToString:
instead of compare: ... == NSOrderedSame
.
精彩评论