2013-11-21 1 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]; 
    } 
} 

내가 아이 비콘에서 오는 두 NSNumbers를 잡는거야, 나는 대응 알이 개 수동으로 세트를 숫자로 비교하고있다. 내가 로그 할 때 번호를 확인하십시오, 동일합니다. 그러나 조건부가 동등한 것으로 간주하지 않으므로 트리거되지 않습니다.

나는 이상한 것을 볼 수 없으며 볼 수있는 것처럼 매우 간단합니다.

의견이나 제안이 있으십니까?

감사합니다. 당신은 다른 메모리 주소로 beaconMinorincommingMinor 점으로 동일하지 않습니다 포인터 주소를 비교하는

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

답변

6

, 당신은 그 (것)들의 값을 비교해야 . 안토니오의 대답

+1

오, 제 커피 시간입니다! 감사. – mrEmpty

+0

:) 괜찮습니다. 나에게도 일어났습니다. –

3

: 당신은 객체 (메모리 주소)을 비교하는

0

(인스턴스의 intValue 비교)에 명시된대로 NSNumber 사용 isEqual:

을 비교하는 경우 정수를 비교하는 경우

는 사용하는 객체의 숫자 값을 비교 ==


if ([incommingMinor isEqual: beaconMinor]) { 

또는

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