views:

131

answers:

1

Hello there,

I have some code which requires an iPhone to run. I do however want to test my app on the simulator. On the iPhone I use this to return a value:

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

I'm looking for something like this I THINK:

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

I want to return a value of 70 for use in the simulator.

Could somebody help me out here?

+5  A: 

Always terminate your +dictionaryWithObjectsAndKeys: with nil otherwise you'll get random crash. If there's only 1 key, it's better to use +dictionaryWithObject:forKey:.


Use #else.

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

Or, more cleanly,

 return [NSDictionary dictionaryWithObject:
         [NSNumber numberWithInt:(TARGET_IPHONE_SIMULATOR ? 70 : -1)]
                                    forKey:@"number"];
KennyTM