2013-11-21 46 views
0

我有一個簡單的條件,其失敗:簡單的條件未能

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]; 
    } 
} 

我抓2個NSNumbers從iBeacon顯示來了,我比較他們,我知道,以對應2個手動組數字。當我登錄它們時檢查數字,它們是相同的。然而,條件不接受它們是平等的,因此不會觸發。

我看不出有什麼不對,這很簡單,正如你所看到的。

任何想法或建議?

謝謝。

回答

6

您比較對象(在內存地址),您需要對它們進行比較的值:

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

Oh jees,time for a coffee I reckon!謝謝。 – mrEmpty

+0

:)沒關係,也發生在我身上 –

3

你比較這將不等於爲beaconMinorincommingMinor指向不同的內存地址的指針地址。

比較對象數值在安東尼的回答(比較實例的intValue

0

說如果你是比較NSNumber使用isEqual:

如果你是比較整數然後用==


if ([incommingMinor isEqual: beaconMinor]) { 

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