0

I've been teaching myself over the last couple of weeks by typing in programs from the iPad books I bought (Backlin's, SAM's, Apps for Dummies, etc.) and YouTube tutorials. Still, there are a couple of things I haven't grasped intuitively. Do you mind helping me out?

I got a program working that saves and retrieves names and phone numbers from pList files. I looked on the Mac's HD and couldn't find the file (Contacts.plist), even though the program was working. I finally discovered it at

~/Library/Application Support/iPhone Simulator

I'm not sure why Finder didn't locate it. My own app needs to load a data file when it starts (questions and answers, for example). Do I write a program to create the Q & A file, (I could modify that phone program to do that) then copy the file into the simulator's virtual directory for my own app? Or do I copy that file into the XCODE Resources folder? Would the data files then travel with the finished executable program?

Sorry to sound so clueless. Thanks for any info. -Rob

vikingosegundo
  • 52,040
  • 14
  • 137
  • 178
Rob Smythe
  • 409
  • 1
  • 3
  • 16

1 Answers1

1

If you want to deliver a file with your finished application, you must add it to your Xcode project. It doesn't matter whether you place it under Resources or in another group in Xcode as Xcode will by default copy all non-code files that are in your project into your finished app bundle.

To access this file from your code, you need to retrieve its path:

NSString *fullPathToContactsFile = [[NSBundle mainBundle] pathForResource:@"Contacts" ofType:@"plist"];

Note that unlike on the iOS Simulator, your app bundle on the device is read only, so if you want your app to make changes to the file, you cannot save it in the bundle itself. In that case, your app should copy the file from your bundle to your app's Documents or Library directory on first launch and then open/save it from/to that location.

Ole Begemann
  • 135,006
  • 31
  • 278
  • 256