Pergunta

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)];
}

Olá, estou tentando salvar até 9 strings e números correspondentes em uma chave de lista de propriedades.Não quero escrever todas as chaves @"Slot Value 1", @"Slot Value 2", etc.

Então, eu queria saber como poderia fazer com que a instrução 'for' inserisse o número inteiro 'x' após cada título a ser salvo nessa chave.

Obrigado.

Foi útil?

Solução

Usar +stringWithFormat::

[valueSavesDictionary setObject:slotValueSave forKey:[NSString stringWithFormat:@"Slot Value %i", (x+1)]];
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top