2010-02-05 48 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"];