返回值对于NSDictionary On Simulator,iPhone

Stu*_*umf 0 iphone objective-c nsdictionary ios-simulator

我有一些代码需要iPhone运行.但我想在模拟器上测试我的应用程序.在iPhone上我使用它来返回一个值:

return [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:-1],     @"number"];
Run Code Online (Sandbox Code Playgroud)

我正在寻找这样的东西我认为:

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

我想返回值70,以便在模拟器中使用.

有人可以帮帮我吗?

ken*_*ytm 6

总是终止你+dictionaryWithObjectsAndKeys:,nil否则你会随机崩溃.如果只有一个键,最好使用+dictionaryWithObject:forKey:.


使用#else.

   return [NSDictionary dictionaryWithObjectsAndKeys:
           [NSNumber numberWithInt:
#if TARGET_IPHONE_SIMULATOR
            70
#else
            -1
#endif
           ], @"number", nil];
Run Code Online (Sandbox Code Playgroud)

或者,更干净,

 return [NSDictionary dictionaryWithObject:
         [NSNumber numberWithInt:(TARGET_IPHONE_SIMULATOR ? 70 : -1)]
                                    forKey:@"number"];
Run Code Online (Sandbox Code Playgroud)