2010-02-05 6 views
0

iPhone을 실행해야하는 코드가 있습니다. 그러나 시뮬레이터에서 내 앱을 테스트하고 싶습니다. 나는 이런 식으로 뭔가를 찾고 있어요반환 값 NSDictionary On Simulator, 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)의 값을 반환 할 아이폰에 나는 값을 반환하려면이 옵션을 사용합니다.

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

답변

6

+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"];