2010-02-05 5 views
0

J'ai un code qui nécessite un iPhone pour fonctionner. Je veux cependant tester mon application sur le simulateur. Sur l'iPhone, je l'utiliser pour retourner une valeur:Valeur de retour Pour NSDictionary Sur simulateur, iPhone

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

Je cherche quelque chose comme ça je pense:

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

Je veux retourner une valeur de 70 pour une utilisation dans le simulateur.

Quelqu'un pourrait m'aider ici?

Répondre

6

Toujours mettre fin à votre +dictionaryWithObjectsAndKeys: avec nil sinon vous aurez accident aléatoire. S'il n'y a qu'une seule clé, il est préférable d'utiliser +dictionaryWithObject:forKey:.


Utilisez #else.

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

Ou, plus proprement,

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