开发者

Compare strings on iPhone fails?

开发者 https://www.devze.com 2023-01-15 15:10 出处:网络
I\'m trying to compare two strings with each other on the iphone, but the IF statement is always false. Here\'s my code:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消