Saving NSString to file

Posted by Michael Amici on Stack Overflow See other posts from Stack Overflow or by Michael Amici
Published on 2010-06-05T20:52:48Z Indexed on 2010/06/05 21:52 UTC
Read the original article Hit count: 277

Filed under:
|

I am having trouble saving simple website data to file. I believe the sintax is correct, could someone help me? When I run it, it shows that it gets the data, but when i quit and open up the file that it is supposed to save to, nothing is in it.

- (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;

}

© Stack Overflow or respective owner

Related posts about xcode

Related posts about saving-data