简体   繁体   中英

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]uniqueIdentifier]);
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

尝试使用stringForKey:而不是valueForKey:isEqualToString:而不是compare: ... == NSOrderedSame

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM