tags:

views:

21

answers:

1

During development, I'd like to have an XML file in my iPhone app's Documents directory when it starts. Is this possible? Having read this answer, I tried adding a Run Script build phase, but I can't find an environment variable that points to the application's home directory after installation. To be clear, the directory I want to move the file to is here, in the case of a Simulator:

/Volumes/Stuff/Users/johnDoe/Library/Application Support/iPhone Simulator/User/Applications/118086A0-FAAF-4CD4-9A0F-CD5E8D287270/Documents

Or here, in the case of a device:

/var/mobile/Applications/30B51836-D2DD-43AA-BCB4-9D4DADFED6A2/Documents

It won't do just to copy the file there manually, because I want to send the source code to someone else so they can see it, and I don't want them to have to do any set-up before they can run it. If what I'm asking isn't possible, then I'll look at ways to move the file programmatically after the app has launched, but I thought I'd check with you guys for a neater way first.

+1  A: 

Do you need to have the file in the Documents directory, or do you just need to have access to it from within the app? In Xcode your current target should have a "Copy Bundle Resources" build phase. Add your .xml file to this build phase and you'll be able to access the file at any point in your code with the following call:

[[NSBundle mainBundle] pathForResource:@"my_file" ofType:@"xml"]
kubi
Oh really? I was put off by the docs, which suggested that resources had to be one of a few set types, not including xml. I'll try what you suggest, and if it works I'll come back and accept your answer. Thanks.
Tommy Herbert
That's working swimmingly. Thanks again.
Tommy Herbert