开发者

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜