I have a file paylines.txt
added inside the folder named TextFiles
which resides inside the Resources
folder of my iOS project in Xcode.
This is the code I use to access the file:
NSString* filePath = [[NSBundle mainBundle] pathForResource:@"paylines" ofType:@"txt" inDirectory:@"TextFiles"];
NSLog(@"\n\nthe string %@",filePath);
The code prints:
2011-06-07 14:47:16.251 slots2[708:207]
the string (null)
I was also having the same problem. The Solution i found is ( in xcode 4.x):
Go to : Target -> "Build Phases" -> "copy bundle Resources" Then add that particular file here. If that file is already added , delete it and add it again.
clean the project and RUN. It works. :)
well i found out the mistake i was committing i was adding a group to the project instead of adding real directory for more instructions
When I drag files in, the "Add to targets" box seems to be un-ticked by default. If I leave it un-ticked then I have the problem described. Fix it by deleting the files then dragging them back in but making sure to tick "Add to targets".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With