Two Face
Two Face

Reputation: 87

How to pass these parameters into an NSString nsuserdefault

I have 14 nsuserdefualt save keys and instead of adding all 14 of them I created a for loop to handle this. However I am getting an error that says too many arguments. I am probably having a brain fart and forgot something. Any tips or suggestions will be appreciated.

Edit: I am trying to read the saved data.

   for (int n=0; n==14; n++ ) {
    NSString *emailBody=[NSString stringWithFormat:@"Enhancers: %@",

                         [[NSUserDefaults standardUserDefaults]
                          stringForKey:@"Enhancer%i",n]];
      }

Upvotes: 2

Views: 116

Answers (1)

Mick MacCallum
Mick MacCallum

Reputation: 130193

You had an extra argument in your format string specifically "n" that should have been placed in a different format for stringForKey:. Something like this should clear things up:

for (int n=0; n==14; n++ ) {
    NSString *stringFromDefaults = [[NSUserDefaults standardUserDefaults] stringForKey:[NSString stringWithFormat:@"%d",n]];
    NSString *emailBody=[NSString stringWithFormat:@"Enhancers: %@",stringFromDefaults];
}

Upvotes: 4

Related Questions