2010-01-25 9 views
1

Je suis perplexe ou tout simplement ne pas trouver les informations dont j'ai besoin, j'ai un objet que je veux enregistrer dans un tableau quand ils sélectionnent "saveDataround", mais je n'arrive pas à comprendre comment remplir l'objet avec le texte "Round": je reçois un "Expected identifier" et "Expected,"; erreurs sur les première et deuxième lignes de code. Merci d'avance.Ajout d'un objet avec "texte"

[NSString *roundChoice = [NSString stringWithFormat:@"Round"]; 
self.round.text = roundChoice;] 

- (IBAction)saveDataround { 
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDirectory = [paths objectAtIndex:0]; 
    NSString *recipient = [NSString stringWithFormat:@"%@/arrayChoiceRound", documentsDirectory]; 
    NSMutableArray *array = [[NSMutableArray alloc] init]; 
    [array addObject:round.text]; 
    [array writeToFile:recipient atomically:NO]; 
} 

Répondre

1

Où sont les deux premières lignes de code implémentées? Que sont-ils censés faire?

Voilà comment je modifier le code ci-dessus sans plus d'info:

// remove "[" from start of line & no need to use stringWithFormat here 
NSString *roundChoice = @"Round"; 

// remove "]" from end of line 
self.round.text = roundChoice; 

- (IBAction)saveDataround { 
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDirectory = [paths objectAtIndex:0]; 

    // use stringByAppendingPathComponent here 
    NSString *recipient = [documentsDirectory stringByAppendingPathComponent:@"arrayChoiceRound"]; 
    NSMutableArray *array = [[NSMutableArray alloc] init]; 

    // use self here (not required) 
    [array addObject:self.round.text]; 

    [array writeToFile:recipient atomically:NO]; 

    // release the array 
    [array release]; 
} 
+0

+1 pour fixer non seulement des erreurs de syntaxe, mais aussi l'amélioration du code. –

+0

Merci, je reçois toujours une erreur: attendu '=', ',', ';', 'asm' ou '__attribute__' avant '.' jeton après self.round.text = roundChoice; –

+0

Désolé, sur les deux premières lignes, je ne sais pas où ils devraient aller ... –