I'm currently trying to create a custom file template for xcode. As part of this any new 'file' from my template actually generates a number of files separated into folders better describing their functionality e.g Foo/Presentation/FooViewController.swift, Foo/DataSource/FooDataSource.swift etc. where 'Foo' is the name of the file created.
Although this works and all the files and folders are added to my project, the folders are added as physical folder references. Is there anyway that in a 'file template' these can be converted to groups? Or is there a way to convert a folder to a group in xcode - I've seen lots of questions doing this the other way but not converting a folder to a group.
I could strip all the folders out, but then as this will be used across a team, everyone would have to create the groups themselves everytime, which isn't a very efficient workflow and a template would ensure a common structure.
I can't seem to find any good docs on template creation either and a lot of the sites online seem focussed on older versions of xcode and project templates rather than file templates.
If anyone has any ideas to help solve this it would be appreciated
To convert the folder structure to a group structure, use the following steps once the folders are created in Xcode:
Delete the folder by selecting "Remove References", so not deleting the files and folders, just its reference inside Xcode.
Select the parent folder and then select Files > Add files to "...".
There, add the just removed folder and make sure you select the option "Create groups".
That will add the full structure of folders and subfolders as groups.
Related
I am working on IBM RDNG 6.0.4. I want to copy (duplicate) all the artifacts of a
project into a single folder. Then create a module from it. Is there any trick to do it? My project has 1000+ artifacts stored in different folders.
Is there any API that can work?
To solve your issue you do not have to use API, because you can do almost everything directly from UI.
1) Create a view that will display all the project requirements.
2) Click on the created view and select option "Edit attributes from view"
3) Select attribute "Folder" for a list of available attributes and change it value to folder of your choice. This will move all your requirements to a single folder.
4) Later you can add those requirement to module using folders filtering or views inside the module.
BTW. DNG does not support adding base artifacts (requirements) to complex structures (modules).
Hope it will help.
In my case I have 50 Folders where each of it has subfolders and images. I could drag them into the apps main bundle but there are many duplicate filenames and it would be more practical to access them in the structured way.
Your wording "it would be more practical to access them in the structured way" seems to suggest that you think the Resources folder cannot contain a folder tree of files, it can. However if you let Xcode itself copy your resource files into the bundle it will flatten the tree without any option to preserve it (for reasons unknown). To address this you can copy the files into the bundle using a build script.
In outline, you need to fill in the gaps with some reading:
First add your files and folders into your project. Use one group per folder, in Xcode 9 creating a group creates a corresponding folder in the project directory but in prior versions you must create the group and then associate it with a folder – check the documentation of whatever Xcode version you are using.
Mark all the folders and files added in this way as not part of your build target. This prevents Xcode copying the files automatically into the bundle, and flattening your folder tree in the process.
Now in the target settings go to the "Build Phases" tab and add a new build script phase. Add a shell script which uses something like ditto to copy the folder tree into the bundle. Various environment variables are set which reference the project and the bundle, check your Xcode documentation or just run a dummy script and dump them out (it is an option, or use printenv). You can use these environment variables to determine the source and destination for your copy.
In your app itself you can locate the root folder of your tree using standard bundle methods. From there you can use whatever method you choose to traverse it/reference items with in it, in exactly the same way you would if the folder tree was not inside the bundle.
HTH
I was just working with a sample project that uses Tesseract OCR library. I followed compiling and building the library as it was mentioned in the link. There the author mentioned precisely to add files one by creating groups and other by creating references. At times we need to carefully check these values or else you will fail to compile. What is actually going on? I just want to know the reasons behind choosing each particular option?
Thanks in advance
If you choose Create groups the files will actually be located in one folder, but in Xcode they will appear grouped the way you had them in the folders.
If you choose Create folder Xcode will create folders in your project directory and the structure will be like the structure of the imported folder/folders.
I have about 20 image files which I would like to a new project. I tried to make my code base clean so I made a group src/img where I intended to place the images.
Then I tried to copy the images via the file system, and obviously the groups that I made did not also create folders. So before I do anything that would dirty-up the code base, I wanted to ask here.
What is the correct way to add the files I want to add so they would render in my group under proj_name/src/img ?
Thanks!
You can first create a folder src/img inside your project in filesystem and copy all of your images in that folder. Then drag the whole img folder to your project in Xcode, but make sure you don't check copy files option when you drag. But, do select the option to create group so that image folder dragged is also a group in Xcode
The filesystem location is not represented by Xcode project groups.
The groups you are creating are supposed to be organized by you, but Xcode also provides useful options like automatically creating groups for the folders checkbox when you are adding new files to the project.
After the files are added to the project, you are free to "move" them to other groups or rename groups, that changes will be stored at the project bundle. Of course if you make the filesystem changes you'll have to remove the broken references from the project and recreate them.
I'm writing an iOS project in Xcode 4 that uses several third-party libraries. One of those libraries contains a file with the same name as a file in my project. I'd like to put both files in separate groups, but it seems like Xcode only allows one instance of each filename in the entire project.
Is there a way around this other than renaming one of the files?
Edit: The files are Objective-C source files (.h and .m). I'm not familiar with mapping groups to folders. How do I tell Xcode to make my groups separate folders on disk?
You can directly Drag & Drop a folder onto the Xcode project and then select Create Folder references for any added.... I don't think you can directly create folders through Xcode. You can however add a Build Phase for copying files which will allow you to create folders in your bundle.