Obj C - Création de clés de liste de propriétés uniques à l'aide de « Pour »

StackOverflow https://stackoverflow.com//questions/9628106

  •  09-12-2019
  •  | 
  •  

Question

for (int x = 0; x < openSlots; x++) {
    NSNumber* slotValueSave = [[NSNumber alloc] initWithInt:[[slotValues objectAtIndex:x] intValue]];
    NSLog(@"Saving slot %@.", (x+1));
    [valueSavesDictionary setObject:slotValueSave forKey:@"Slot Value %i", (x+1)];
}

Bonjour, j'essaie d'enregistrer jusqu'à 9 chaînes et les numéros correspondants dans une clé de liste de propriétés.Je ne veux pas écrire chaque clé @"Slot Value 1", @"Slot Value 2", etc.

Je me demandais donc comment faire en sorte que l'instruction « pour » insère l'entier « x » après chaque titre à enregistrer sous cette clé.

Merci.

Était-ce utile?

La solution

Utiliser +stringWithFormat::

[valueSavesDictionary setObject:slotValueSave forKey:[NSString stringWithFormat:@"Slot Value %i", (x+1)]];
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top