Durdu
Durdu

Reputation: 4849

How to list all files for one target in Xcode

Is there a XC command I can use to list all files for one target?

enter image description here

Upvotes: 5

Views: 1360

Answers (1)

Brad Allred
Brad Allred

Reputation: 7534

Unfortunately, I'm unaware of any environment variables available to a build script.

The best way that I know of would be to open the pbxproj file inside your xcodeproj bundle and parse it. Luckily, it seems to be in a plain text format compatible with plists. You could invoke the plutil command to convert it to XML or json for another tool/command to consume if that is your goal. You can utilize a "Run Script" build phase if you need this list as part of your build. You can also instantiate an NSDictionary directly with that file if that is useful to you.

The plist is pretty simple. It consists of a root dictionary with some version strings and a giant objects dictionary. Each object has an isa type and the one you are interested in is the PBXNativeTarget type. Scan until you find the target with the correct value for the name key. Once you find your target look at its buildPhases; AFICT the first entry in buildPhases is the key for the corresponding PBXSourcesBuildPhase object. That build phase object has a files array which contains yet another set of IDs (one for each file compiled into the target) which point to a PBXBuildFile object, which has a fileRef string as a key to another object, this time to a PBXFileReference. This object finally has a path key which will be the path to the source file.

Wait... did I say "simple"?

Upvotes: 2

Related Questions