Megaetron Megaetron - 1 year ago 43
Swift Question

How to access a added pdf file after archiving the project to copy it into users documents folder?

I want to copy a pdf file with the license agreement of my app into the documents folder of the user. I know how to access the documents folder of a user and how to copy a file but which path or 'NSURL' is the correct one for the pdf file?

I copied the pdf file into the project folder of the app and added the file with "Add files to "MyProject"..." to the project. Normally I would choose the path where the pdf is located e.g.

but thats only the path for my Mac. How can I change the path so that it works on every Mac?

Please answer in swift language.

Answer Source

Following is how you can reference a local file embedded within the project,

[[NSBundle mainBundle] URLForResource:@"FILE NAME" withExtension:@"pdf"];