Search code examples
iphoneiosnsfilemanagerfilehandle

filehandle options not coming up


I have typed the following code in from a tutorial and i cannot get it to work... It says "No visible @interface for 'NSFilemanager' declares the selector ..... for the [fileHandle seekToEndOfFile]; [fileHandle writeData:[resultLine dataUsingEncoding:NSUTF8StringEncoding ]]; [fileHandle closeFile]; sections..

Any idea what the problem is as ive gone through it many many times.. Thanks Mat

 - (IBAction)SaveText:(id)sender {

NSString *resultLine =[NSString stringWithFormat:@"%@\n",
                       self.inputText];

NSString *docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask,YES)objectAtIndex:0];
// textMsg.text = docPath;

NSString *savedTextMsg =[docPath stringByAppendingPathComponent:@"textMessage.csv"];

if (![[NSFileManager defaultManager] fileExistsAtPath:docPath]) {
    [[NSFileManager defaultManager]
     createFileAtPath:savedTextMsg contents:nil attributes:nil];
}
NSFileManager *fileHandle = [NSFileHandle fileHandleForUpdatingAtPath:savedTextMsg];
[fileHandle seekToEndOfFile];
[fileHandle writeData:[resultLine dataUsingEncoding:NSUTF8StringEncoding ]];
[fileHandle closeFile];

self.textMsg.text =@"";
NSLog(@"info saved");

}


Solution

  • It would help if you changed:

    NSFileManager *fileHandle = [NSFileHandle fileHandleForUpdatingAtPath:savedTextMsg];
    

    to:

    NSFileHandle *fileHandle = [NSFileHandle fileHandleForUpdatingAtPath:savedTextMsg];
    

    Note the variable's type.