문제

iPhone을 실행 해야하는 코드가 있습니다. 그러나 시뮬레이터에서 내 앱을 테스트하고 싶습니다. iPhone에서 나는 이것을 사용하여 값을 반환합니다.

return [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:-1],     @"number"];

나는 다음과 같은 것을 찾고 있습니다.

- (NSDictionary *) data
{
#if TARGET_IPHONE_SIMULATOR
something in here to return a value of 70;
#else .....

시뮬레이터에서 사용하기 위해 70의 값을 반환하고 싶습니다.

누군가 나를 도와 줄 수 있습니까?

도움이 되었습니까?

해결책

항상 당신을 종료하십시오 +dictionaryWithObjectsAndKeys: ~와 함께 nil 그렇지 않으면 무작위 충돌이 발생합니다. 키가 1 개 밖에 없다면 사용하는 것이 좋습니다. +dictionaryWithObject:forKey:.


사용 #else.

   return [NSDictionary dictionaryWithObjectsAndKeys:
           [NSNumber numberWithInt:
#if TARGET_IPHONE_SIMULATOR
            70
#else
            -1
#endif
           ], @"number", nil];

또는 더 깨끗하게

 return [NSDictionary dictionaryWithObject:
         [NSNumber numberWithInt:(TARGET_IPHONE_SIMULATOR ? 70 : -1)]
                                    forKey:@"number"];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top