Search code examples
xcoderesourcesbundle

Xcode: what is a good way to replace a resource file?


I have an iPhone application that is compiled under Xcode. I have a file which I shall call 'manual.pdf'. The app has a manual page that shows manual.pdf using WKWebView. The 'manual.pdf' file is generated from OfficeLibre.

When the UI has changed, I go through the original 'manual.odt' replacing the screen shots with new ones, and correcting the text. I then export a new 'manual.pdf'. I then have to...

  • delete the old 'manual.pdf' entry.
  • drag the new file to the Resources directory.
  • fill in the form to get it added.

I don't need a build-time copy script. Those look complicated, and this is not particularly labour intensive, and I don't necessarily want to do it every time the manual changes. But this feels wrong. I would be happy if Xcode just substituted the new file for the old file if it had the same name. But it doesn't.

I am running Xcode 14.1 building for an iPhone 12 running iOS 16.0 FWIW.


Solution

  • I found the answer. I had just edited the file, and I went to Xcode to update the reference. The new version was already there. I guess when I dragged the file, it created a link rather than copying the file.

    Nice, once you know it is there.

    PS:

    I have made another discovery. Xcode used the latest 'manual.pdf' when building the application, but it did not save it when I committed the changes. I had to separately update the PDF file in the git archive to get it to update. However, the builds released to the TestFlight site all had the right PDF.

    My minimal solution is to copy the file to the archive...

    cp ~/Documents/manual.pdf ~/XcodeProjects/MyApp/MyApp/Resources/
    

    This then gets committed with the next Xcode commit.