Question

IOS development... I have a json data file named "Data.js" in the same directory where the code file is and is trying access it with the following code...

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Data" odType:@"js"];

but this is returning null.

Any help on this is much appreciated.

Was it helpful?

Solution

The above written answers are right. By default Data.js file will be added to the compilation phase. You can drag that to the Copy Bundle Resources phase. FYI i'am adding a reference screen shot. Go to the settings page of your target under Build phases you can find these sections. Drag the selected file to Copy Bundle Resources phase

enter image description here

OTHER TIPS

Did you check whether Data.js has been added to copy bundle resources under build phases?

enter image description here

When you add JS files Xcode will add them to the compilation phase (since they're code files), instead of the Copy Bundle Resources phase. You need to go to your project settings and move it to the right phase.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top