I’m trying to import a text file into my iPad application using the method initWithContentsOfFile:encoding:error:, but when I try to get the filepath to my text file, I am running into some troubles. It seems that my text file is not being found. The following call returns nil (the text file is called legal.txt)
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"legal"
ofType:@"txt"];
Obviously, after this returns nil, my call…
NSString *fileContents = [[NSString alloc] initWithContentsOfFile:filePath
encoding:NSUTF8StringEncoding
error:@"error"];
also returns nil.
I am quite new at this so I might be doing something obviously incorrect, but looked all over SO and elsewhere and couldn’t find anyone with the same problem as me.
Call pathForResource:ofType:inDirectory:
by passing the directory as well