Reputation: 10817
To access the resource file namefile
from a program:
I ostensibly just need to check the box "target membership" to identify it as a resource file:
but this box is disabled.
What am I missing?
Upvotes: 2
Views: 965
Reputation: 1394
Add the file to the "Copy Files" section of your project's Build Phases:
Make sure to set Destination
to "Resources", clear Subpath
, and untick Copy only when installing
.
Then whenever you build, Xcode will copy the file into your app's build directory, right next to the executable:
That's a screenshot of the ~/Library/Developer/Xcode/DerivedData/[your project]/Build/Products/Debug
folder.
This method also works when you archive your app.
Note: if you want the file to be in some subfolder relative to the executable, e.g. res/images/
, set the Subpath
to that path.
Upvotes: 0
Reputation: 17724
The helloworld
target in your project is configured as a command-line tool (the square black icon that looks like a Terminal indicates this). Those compile to a single, standalone file thus Xcode cannot embed a resource file with it (which is why it's disabled).
You need to build a "Cocoa Application" target if you want to be able to include resource files. You can start a new project using the Cocoa Application template or manually add a target to your current project. You'll probably find it easier to start with a new project.
Upvotes: 1