PDA

View Full Version : What is wrong in this code? NSArrays




alexandergre
Aug 8, 2009, 01:26 PM
xcode says it has no errors but it does. This code is to add Highscore to the Highscore list.
Is this really the simplest way?
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0)
{
NSLog(@"Score saving cancelled");

}
else
{
NSLog(@"Adding score...");


NSMutableArray *ScoresArray= [NSMutableArray array];;
NSMutableArray *NamesArray= [NSMutableArray array];;
NSLog(@"Arrays created");

NSString *NameToSave = SaveName;
NSString *ScoreToSave= [NSString stringWithFormat:@"%d", points];
NSLog(@"Strings created");

[ScoresArray addObject:ScoreToSave];
[NamesArray addObject:NameToSave];
NSLog(@"Added to Arrays");

NSUserDefaults *ScoresDefaults =[NSUserDefaults standardUserDefaults];
[ScoresDefaults setObject:NamesArray forKey:@"NamesKey"];
[ScoresDefaults setObject:ScoresArray forKey:@"ScoresKey"];
NSLog(@"Score saved in NSUserDefaults");

}
}



Guiyon
Aug 8, 2009, 02:42 PM
xcode says it has no errors but it does.

What exactly is it not doing?

ritsard
Aug 10, 2009, 12:40 PM
NSMutableArray *ScoresArray= [NSMutableArray array];;
NSMutableArray *NamesArray= [NSMutableArray array];;

Typically, you should only have one semi-colon at the end...unless this is something new.

-aggie-
Aug 10, 2009, 12:52 PM
Typically, you should only have one semi-colon at the end...unless this is something new.

Yes, but I doubt that would cause a problem, since it just means end of line. I just added another semi-colon to the end of one of my codings and I got no errors.

dejo
Aug 10, 2009, 12:56 PM
Still waiting for the OP to respond to post #2...