Adding non-Swift files to target

I am developing a game, which will run on macOS, iOS and tvOS
Building the code and setting the target per file for .SWIFT files is no problem
I just dragged a few hundred files (in various folders)... these files have extensions of .MAP or .TXT

the .TXT allow me to set the target, but the .MAP files do not

What are in the .map files? The .map file suffix is tricky with both Xcode and MacOS. If Xcode can't make heads or tails of what's in the file, or that it doesn't match what it expects (module maps in particular), it won't handle them correctly.

You do know that Xcode doesn't just handle Swift. C,C++,ObjC,ObjC++,Ruby, Python,Java all have varying levels of support in Xcode. So, for example, if for some reason you want to add a file named "file.h", Xcode is going to assume that the file contains a C/C++/ObjC/ObjC++ header, even it doesn't. Xcode uses the suffix to figure out what type of editor it needs to call up to handle the contents of the file. And, that figures into what files can be associated with a target.

It seems like the map files (maybe the text files) are support files for your application. If so, unless you are planning to edit these files, you might want to create a "Build Resource Folder" build phase for each of your targets, and drag 'n drop those files into the dialog boxes. Xcode will build a Resource folder for each target and copy those files into that folder. Under the macOS/iOS/tvOS architecture, that's where these support files belong. You get the file path for the resource folder at runtime using Foundation routines on NSWorkspace/NSBundle and you use that as the directory name component for the specific file you want to open at the time.

Thanks.... The "map" files are just ASCII text that describe level maps for a game...
There are like 300 .MAP files, each with another .TXT file that contains description/instructions for each level.

Is there a way to mark a target for a mass selection of files (assume .TXT) or do I have to do them one at a time?

All of these files need to belong to ALL targets

Consider changing the file suffix from .map to .map.txt. They will then be recognized as text files and you should be able to assign target membership, if that is what you want. If you work through the GUI, specifically the Navigator (panel on left), you can select a range of them using cmd-mouse and/or shift-mouse, then you can click once to change them all. Otherwise, it is one at a time.

When I have a folder full of stuff that I just want Xcode to copy into my app I add that to my project as a folder reference rather than a group. That is, in the File > Add Files UI I select “Create folder references” rather than “Create groups”. The resulting folder reference acts as a single item that you can add to any target. It ends up in the target’s Copy Bundle Resources build phase and gets copied en masse to the app’s Resources directory.

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple

1 Like