简体   繁体   English

比较iPhone上的字符串是否失败?

[英]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. 我正在尝试在iPhone上比较两个字符串,但是IF语句始终为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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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