10

Xcode Copy Files Build Phase Destinations

The Xcode docs for this don't explain exactly where each of the Destination paths maps to on disc, relative to my application package.

If I use this app as an example, could someone give a canonical answer where each will put files relative to this directory structure?

Xcode directory structure

pkamb
  • 33,281
  • 23
  • 160
  • 191
Mr. Boy
  • 60,845
  • 93
  • 320
  • 589
  • Is that directory the *app bundle* (which is what the *Copy Files* configuration is referring to)? – trojanfoe Oct 03 '13 at 10:17
  • Sorry, this is the 6.1 subdirectory of the Users/$User/Library/Application Support/iPhoneSimulator directory... so this is what XCode installs for the simulator. `Viewer` is the app bundle itself if I have my terminology correct. – Mr. Boy Oct 03 '13 at 10:20
  • I don't believe they are the same thing; Xcode wants to know where within the app bundle you want the file copied and what you show is the app's container folder. I'm not 100% sure however. – trojanfoe Oct 03 '13 at 10:21
  • Well, all I'm after is a clear answer where, relative to either View or /891E4861-... each of those destination options will put the files. Are those options literally the names of sub-folders like "Java Resources"? Which is the "Products Directory"? etc – Mr. Boy Oct 03 '13 at 10:28
  • Not sure. Not sure it matters these days as I think everything will go beneath `Resources` anyway. – trojanfoe Oct 03 '13 at 10:29
  • 1
    Of course it matters, I need to know the path to access the files in the app! – Mr. Boy Oct 03 '13 at 10:34
  • No, I don't think it does matter. Anyway why not try it and see where the file goes into the app bundle? – trojanfoe Oct 03 '13 at 10:38

1 Answers1

8

The app bundle in your example is Viewer. This is not a file; it's a directory. If you click on it and "Show Package Contents", you'll see the rest of it.

Products Directory is the directory that Viewer is written to. You cannot write to this directory in iOS.

For iOS, Wrapper is the top level directory within Viewer.

For iOS, Executable is the same directory as Wrapper.

For iOS, Resources go into either the Wrapper directory, or the localization directories (Base.lproj, etc) if the resource is localized.

The other directories aren't meaningful for iOS.

Still, you should use the directories logically. Use "Executable" to mean "the directory where my executable lives." Don't assume that the directory tree is laid out a particular way internally.

Regarding your comment that you need to know the path to access the file, you do not need that (and shouldn't try). You should use [NSBundle pathForResource:ofType:] to find files.

mfaani
  • 33,269
  • 19
  • 164
  • 293
Rob Napier
  • 286,113
  • 34
  • 456
  • 610
  • This is a C++ application using cross-platform libraries which use regular paths and think in terms of directories and files. I'll add the `C++` tag since I didn't realise this was different in pure iOS dev. – Mr. Boy Oct 03 '13 at 14:23
  • 1
    You should still use the bundle to find the path for you. Do not try to construct it based on assumptions about the tree. You can use `NSBundle` in ObjC code and pass the resulting string, or you can use `CFBundleCopyResourceURL` in pure C or C++ code. – Rob Napier Oct 03 '13 at 14:45
  • Cross-platform libraries often doesn't give you that luxury (I'm using Ogre3D here), in my case I use iOS APIs to get the absolute path of the bundle and have to do everything relative to that. It works fine (touch wood!), are there official guidelines against this? – Mr. Boy Oct 03 '13 at 15:13
  • If you're using `[NSBundle resourcePath]` to find your resources, then you are free to read subdirectories off of that. Just don't make assumptions about where `resources` is relative to the `bundlePath`. Almost every root path you want is available in via `NSBundle`: https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSBundle_Class/Reference/Reference.html#//apple_ref/occ/instm/NSBundle/resourcePath. And you of course can pass these into C++ libraries (I do this all the time). – Rob Napier Oct 03 '13 at 15:21
  • Ah, in this case we may be talking at cross-purposes a bit. Thanks for the help. – Mr. Boy Oct 03 '13 at 15:28
  • Just wanted to also mention this great [doc](https://developer.apple.com/documentation/xcode/customizing-the-build-phases-of-a-target) on that "The Copy Files build phase supports the following destination directories:" products, wrapper, executable, resources, Java resources, Frameworks, Shared Frameworks, Shared Support, Plugins, XPC Services, System Extensions, App Clips – mfaani Jan 18 '23 at 02:20