Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to create and write to file using NSFileHandle... and it doesn't seem to be working

What am I doing wrong here:

NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0]; 
self.gpsFilePath = [documentsDirectory stringByAppendingString: @"/gpsReadings.txt"];
self.gpsFile = [NSFileHandle fileHandleForWritingAtPath:self.gpsFilePath];
[self.gpsFile writeData:@"GPS Readings"];
[self.gpsFile closeFile];
like image 752
Andrew Johnson Avatar asked Jul 12 '09 23:07

Andrew Johnson


1 Answers

I need to create the file first:

[[NSFileManager defaultManager] createFileAtPath:self.gpsFilePath contents:nil attributes:nil];
like image 189
Andrew Johnson Avatar answered Sep 20 '22 14:09

Andrew Johnson