0

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.

Midhun MP
  • 103,496
  • 31
  • 153
  • 200

3 Answers3

1

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

Anil Varghese
  • 42,757
  • 9
  • 93
  • 110
  • Thank you so very much Anil. This is solved now. Going further I have issue with reading the data from that file. I will ask for that in a separate thread. Thanks to all of the respondents!! – Ashish Priyadarshi Sep 25 '13 at 01:50
0

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

enter image description here

Satheesh
  • 10,998
  • 6
  • 50
  • 93
0

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.

Guy Kogus
  • 7,251
  • 1
  • 27
  • 32
  • Where can I find this option? I tried looking in the project's Build settings but could not find. I am quiet new to this so unable to figure out. PLease let me know the steps. – Ashish Priyadarshi Sep 24 '13 at 11:38
  • Look at Anil's response above. It's in Build Phases, not Build Settings. – Guy Kogus Sep 24 '13 at 13:08