Search code examples
xcodexcode7

How do I access a resource file in Xcode?


To access the resource file namefile from a program:

main.cpp

I ostensibly just need to check the box "target membership" to identify it as a resource file:

target membership

but this box is disabled.

What am I missing?


Solution

  • 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.