ios - What is the correct way to add outside files to my new project? - ios

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.

Related

Folder structure of xCode project is not appearing in git repository

I'm developing an iOS app with some other students of my class. One of them created our Xcode project and set up all the folders (groups) we need. These folders also appear in his finder. When pushing everything the folders are not visible in our repo. When I pull it, everything in Xcode is fine, all the folders are there (which also says the pbxproj-file). BUT in my finder none of these folders are there.
This is how it looks like
How can we also put the folders in Git, so that they are visible in our repo and the files are in them?
Edit: The below is the question I thought you were asking, but the image you added suggests a different problem. I would first make sure you're actually looking at the same directory. Cmd-rightclick the project in the navigation bar and make sure it's the folder you think it is. This is a surprisingly common mistake.
I would then make sure you haven't referenced external folders or put things in a strange place. Select a folder and open the right-hand sidebar (Cmd-Opt-1), and check the path. It is very common when you drag things into a project, or rearrange a project by dragging, to accidentally create absolute path references to locations outside your project.
Xcode has traditionally used groups rather than folders to organize files. Groups are a virtual structure, purely in Xcode. Most of the files are put into a single physical directory.
(Whether this is good or bad is a matter of taste. I've long preferred having most files in one directory to make reorganizing the structure easier, and to make it easier to write scripts that search or process all the source code. But over the years, and particularly moving to Git from Perforce and SVN, and especially with the rise of GitHub, I've grown to prefer the folders, and that seems to be the direction Apple is moving towards as well.)
In recent versions, Xcode has moved towards supporting folders directly.
You can see the difference in Xcode. This is a group without a folder:
This is a group with a folder:
Note the lower-left corner of the icon.
You can make folders from the local menu, either by right-clicking an existing folder/group, or by selecting files you would like to move into a folder and right-clicking:
I don't believe there's any shortcut to convert all existing groups into folders. You'll have to restructure. But as you create new things, make sure to create folders if you want those.
It's better to maintain relevant folder structure as mentioned by #Rob Napier so that when you modularise/move files in xcode the files are moved to the corresponding folder structure and they are in sync with the file system.
Right click on any one of the file(under view/vm) and -> click show in finder to check the absolute path of the file.

copy all artifacts in a project to a new folder and create a module from them in IBM RDNG

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.

xcode create group from physical folder based on file template

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.

Some files are located outside of "MyApp" directory in my iOS app - why?

I'm now developing my first iOS app, and I found that two of my classes (hence, four files) are located outside of my MyApp/.
So in my filesystem, here's the current situation:
My App
- ClassA.h
- ClassA.m
- ClassB.h
- ClassB.m
MyApp/
MyApp.xcodeproj/
MyAppTests/
Other than the two classes, all of my class files are located in MyApp subdirectory. The other resources, such as Core Data model file or images are saved in the same directory.
However, why are the two classes, and only the two classes, located in the outside of MyApp subdirectory? When I move those files to the supposedly correct location, those files are no more "valid" in Xcode with the color of the file name is converted to red.
So here's my question:
Why are those two files located there?
Do they have any issues if they remain to be located there?
Should I fix this issue and save it correctly? I think I haven't had any issues so far with the Simulator and the actual iPhone...
I use iOS 7 and Xcode 5.
•Why are those two files located there?
A: When you have created these files or imported from external directory, you may have not taken care of the group/folder these files are getting created/imported into. Hence they are inside the main app folder in the file system.
•Do they have any issues if they remain to be located there?
A: No, this is certainly not an issue in the correct functioning of your app, but it is always good to manage your files under groups/folders for better file structure and it is easier to find files when they become large in number.
•Should I fix this issue and save it correctly? I think I haven't had any issues so far with the Simulator and the actual iPhone...
A : This depends on you. If you like to keep your files in folders and like everythin arranged in some pattern, then yes you can divide the app into different folders. When you move the files in a folder, the reference of those in XCODE should change as well, and thats why you see those files in red in XCode. No worries. Just delete the files and add them again. Make sure you uncheck the option "Copy files under detsination group's folder".
Now, you may seem the option of creating New Groups inside XCode. But it is good to be aware that these groups do not create separate folders inside file system. These are just for Xcode refernce. So, a neat way is to create folders outside of XCode, and then import these folders(can be empty) in Xcode. Now when you add any file in these imported folders, even from XCode, it will go inside the correct folder in file system.
I am sorry I am not on my MAC right now, so cannot paste actual images, showing how to do it. Feel free to comment, if I have instead of solving the issue, have rather confused you more:D
You can put your source files wherever you want, as long as Xcode knows where to find them. You can leave them here, or organize it in another way, as you seem to be willing to do.
So, if you want to move these files in your Myapp/ subfolder, just move them there, and when Xcode complains it can't find them, highlight all those files in red in the navigator, and in the "File inspector" pane (right hand side of the window), click on the little Folder icon to browse to the new location. If you selected all files you don't need to do that 4 times, Xcode will find it out by itself.

Managing visual assets on xcode (reference, copy or both)?

Good evening overflowers,
I was wondering what would be the best way to manage assets (visual, sound, etc.) in xcode for ios or mac os projects.
I am currently working on a project that the image files change all the time (design is under construction still) and I would like to know the best way to keep all the files updated while having them in the project's directory.
So for instance I have a file named "ic_action_gray_button#2x.png" This button changes on the design but still has the same name. Is there a magical way to mirror the changes and have it also under source control without spending time finding and replacing the file all the time?
It is something easy when it comes to 50 assets but when these assets become 100 or 500 then, it becomes difficult to keep up with the changes.
Any tutorial or any guide to help me through this process?
If my question is not clear, be easy on me, I am not a native English speaker :)
Kind Regards,
Sonic555gr
You can create a separate folder for your assets inside your project folder. Then you can drag your asset folder to your project in Xcode, select "Create folder references for any added folders" and uncheck "Copy items into destination group's folder (if needed)". This should serve your purpose.
The way I do it is just to take the 100 - 150 or however many assets and paste them in Finder.
As long as the files have the same names, you are just doing an overwrite in Finder, inside the folder of your XCode project.
Any new images, you can add to XCode as usual, by drag & drop, then selecting copy and choosing the target. Any replacements can be done in Finder after that.
Git will also detect the file modifications and you can push the changes to your repo. For file/assets replacements, there is no need to do it through XCode and add the new images again.
If you are using asset catalogs for your images, its just a matter of replacing the files inside the specific folders, which is tedious, its then easier to just select them all inside XCode, delete them from the catalog, and from the project, and then just drag and drop them into the asset catalog again.

Resources