[英]NSNumber equivalence error in iOS
I'm trying to find beacons in range and sort UITableViewCells hereafter. 我试图在此后找到信标,并对UITableViewCells进行排序。 I am trying this;
我正在尝试
NSLog(@"Trying (%@ = %@, %@ = %@)",major, beacon1.major,minor, beacon1.minor);
if(beacon1.major == major && beacon1.minor == minor){
NSLog(@"%@;%@ is first",major,minor);
[room insertObject:room atIndex:0];
}
This means that if NSNumber Major and NSNumber Minor are equal to found beacon, the if will be run. 这意味着如果NSNumber Major和NSNumber Minor等于找到的信标,则将运行if。 NSLog Retuns this:
NSLog重新调整此内容:
2015-01-02 12:33:02.277 App[468:30045] Trying (47566000 = 47566, 39534000 = 39534)
2015-01-02 12:33:02.278 App[468:30045] Trying (47566000 = 47566, 39534000 = 39534)
2015-01-02 12:33:02.279 App[468:30045] Trying (47566 = 47566, 39534 = 39534)
I would hereafter expect it to run the third time. 此后,我希望它能够第三次运行。 But it does not.
但事实并非如此。
Do anyone have a clue whats going on here? 有人知道这是怎么回事吗?
You are comparing for variable instance equality, not the contained values. 您正在比较变量实例是否相等,而不是所包含的值。
Use isEqualToNumber: instead. 使用isEqualToNumber:代替。 See documentation .
请参阅文档 。
The code should look like this: 该代码应如下所示:
if ([beacon1.major isEqualToNumber:major] && [beacon1.minor isEqualToNumber:minor]) {
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.