0

iPhone を実行する必要があるコードがいくつかあります。ただし、シミュレーターでアプリをテストしたいと思います。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 の値を返したいです。

誰か私をここで助けてくれませんか?

4

1 に答える 1

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"];
于 2010-02-05T14:57:22.473 に答える