I am trying to read a text file line by line, and the text file will be a really small file so I just used:
NSString *fileContents = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
However, an exception is raised on that line, saying:
[NSURL getFileSystemRepresentation:maxLength:]: unrecognized selector sent to instance 0x7f92c40e1890
I’m really new to Objective-C and I don’t get why this is happening…
Thanks in advance.
NSString *filePath;
NSOpenPanel *fileBrowser = [NSOpenPanel openPanel];
[fileBrowser setCanChooseFiles:YES];
[fileBrowser setCanChooseDirectories:YES];
if ([fileBrowser runModal] == NSOKButton) {
NSArray *files = [fileBrowser URLs];
for ( int i = 0; i < [files count]; i++ ) {
filePath = [files objectAtIndex:i];
}
}
Is this because of the [fileBrowser URLs] part?
Thank you.
It looks like
filePathis anNSURL, butstringWithContentsOfFile:encoding:error:expects the path as anNSString.Try this: