ios - 简单的条件失败

标签 ios objective-c conditional-statements

我有一个失败的简单条件:

 NSNumber *beaconMajor = [NSNumber numberWithInt:33995];
NSNumber *beaconMinor = [NSNumber numberWithInt:59204];
NSNumber *incommingMajor = beacon.major;
NSNumber *incommingMinor = beacon.minor;

NSLog(@"%d", [beaconMajor integerValue]);
NSLog(@"%d", [incommingMajor integerValue]);

NSLog(@"Pre big conditional");

//if the beacon is the one for the test content AND we are very near to it, show that content
if (incommingMinor == beaconMinor) {
    NSLog(@"Into big conditional");
    if (beacon.proximity == CLProximityImmediate) {
        [self performSegueWithIdentifier:@"mainToContent" sender:self];
    }
}

我正在从 iBeacon 中获取两个 NSNumbers,并将它们与我知道对应的两个手动设置的数字进行比较。当我记录它们时检查数字,它们是相同的。但是,条件不接受它们相等,因此不会触发。

我看不出有什么不对,就像你看到的那样很简单。

有什么想法或建议吗?

谢谢。

最佳答案

你在比较对象(内存中的地址),你需要比较它们的值:

if ([incommingMinor intValue] == [beaconMinor intValue])

关于ios - 简单的条件失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20119699/

相关文章:

ios - 使用 popViewControllerAnimated(true) 导航出 UITableView 时如何修复 UISearchController 的警告

javascript - WebRTC 在 iOS 中与 OWN 服务器的集成

ios - NSMutableArray 从 viewDidLoad 初始化

objective-c - iOS EXC_BAD_ACCESS 类中的错误

ios - 以全分辨率从 UIScrollView 中捕获缩放的 UIImageView

ios - 如何将 UInt32 转换为 UInt8

ios - 一起使用 Google Analytics SDK 和 Firebase SDK

Ruby slim 内联 if

javascript:评估多个 if 语句而不运行 else

assembly - ARM IT条件指令汇编器(armcc)