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

Hello, I'm trying to saving up to 9 string and corresponding numbers to a property list key. I don't want to write out every key @"Slot Value 1", @"Slot Value 2", etc.

So I was wondering how I could have the 'for' statement insert the 'x' integer after every title to be saved under that key.

Thank you.

Was it helpful?

Solution

Use +stringWithFormat::

[valueSavesDictionary setObject:slotValueSave forKey:[NSString stringWithFormat:@"Slot Value %i", (x+1)]];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top