2010-02-05 22 views
0

我有一些代碼需要運行iPhone。不過我想在模擬器上測試我的應用程序。在iPhone上我用這個返回值:返回值對於模擬器上的NSDictionary,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終止,否則你會得到隨機崩潰。如果只有一個密鑰,最好使用+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"];