Xcode Copy Files Build Phase - what do the "Destination" options mean?

10,112

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

Share:
10,112
Mr. Boy
Author by

Mr. Boy

SOreadytohelp

Updated on June 17, 2022

Comments

  • Mr. Boy
    Mr. Boy almost 2 years

    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

    • trojanfoe
      trojanfoe over 10 years
      Is that directory the app bundle (which is what the Copy Files configuration is referring to)?
    • Mr. Boy
      Mr. Boy over 10 years
      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.
    • trojanfoe
      trojanfoe over 10 years
      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.
    • Mr. Boy
      Mr. Boy over 10 years
      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
    • trojanfoe
      trojanfoe over 10 years
      Not sure. Not sure it matters these days as I think everything will go beneath Resources anyway.
    • Mr. Boy
      Mr. Boy over 10 years
      Of course it matters, I need to know the path to access the files in the app!
    • trojanfoe
      trojanfoe over 10 years
      No, I don't think it does matter. Anyway why not try it and see where the file goes into the app bundle?
  • Mr. Boy
    Mr. Boy over 10 years
    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.
  • Rob Napier
    Rob Napier over 10 years
    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.
  • Mr. Boy
    Mr. Boy over 10 years
    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?
  • Rob Napier
    Rob Napier over 10 years
    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: developer.apple.com/library/ios/documentation/Cocoa/Referenc‌​e/…. And you of course can pass these into C++ libraries (I do this all the time).
  • Mr. Boy
    Mr. Boy over 10 years
    Ah, in this case we may be talking at cross-purposes a bit. Thanks for the help.