J'ai des difficultés à enregistrer des données de site Web simples dans un fichier. Je crois que le sintax est correct, quelqu'un pourrait-il m'aider? Quand je l'exécute, cela montre qu'il obtient les données, mais quand je quitte et que j'ouvre le fichier auquel il est censé sauvegarder, rien n'y est.Enregistrement de NSString dans le fichier
- (BOOL)textFieldShouldReturn:(UITextField *)nextField {
[timer invalidate];
startButton.hidden = NO;
startButton.enabled = YES;
stopButton.enabled = NO;
stopButton.hidden = YES;
stopLabel.hidden = YES;
label.hidden = NO;
label.text = @"Press to Activate";
[nextField resignFirstResponder];
NSString *urlString = textField.text;
NSData *dataNew = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlString]];
NSUInteger len = [dataNew length];
NSString *stringCompare = [NSString stringWithFormat:@"%i", len];
NSLog(@"%@", stringCompare);
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"websiteone" ofType:@"txt"];
if (filePath) {
[stringCompare writeToFile:filePath atomically:YES encoding:NSUTF8StringEncoding error:NULL];
NSString *myText = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:NULL];
NSLog(@"Saving... %@", myText);
}
else {
NSLog(@"cant find the file");
}
return YES;
}