How can I arrange my project files according to their folder structure in Xcode - ios

I am working on a MASSIVE project with about 10 thousand files in it. The files are nicely arranged in Xcode's directory system but not so on the disk. Is there a tool that I could use that would make the folder structure on my disk represent the folder structure in Xcode?

Personally, I know two ways to do it:
Do it manually (rearrange your folder first, and then drag and drop your directories in xcode). That will do the job.
Use an external library, I suggest you synx. It does the job well
I don't know why you want to do that, but I don't think it's really important if your folder isn't ordering with your xcodeproj since you will always open it with xcode. Just separate assets is enough, isn't it?

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.

XCode Project: should we put source code in separate folders for meaningful purpose

I'm a Java developer, and a new comer to ios development. In learning phrase, I try to download some sample projects (include from small one to medium one) for reading how often they do work in an ios project. As I see, often, they put all source file into one folder (include header file, source file, .storyboard file, xib file ...) and I see this will make your project become messy.
So, I come here to ask a question that. Should we put source code in separate folders base on their usage, to make project less messy, right ? For example, all custom core data model class files should put into Model folder. All View file (such as .storyboard, .xib file ...) should put into View folder. All Controller file should put into Controller folder ...
If you often do this, please tell me your experience, how you folder your code ? And does XCode support virtual folders (that in XCode IDE you see source code in folders, but in hard drive, they're just same).
Thanks :)
Xcode differs from Eclipse and Android Studio in maintaining a separate project-level division of resources into folders that need have no correlation whatsoever to the file system. Given that the lack of namespaces usually leads people to be very relaxed about what formally is and is not a 'package', it's a real wild west out there.
I tend to keep things organised by mental package — model, view, controller at the top level, e.g. maybe web services, persistent store under model, etc. But even then command+shift+O and type a symbol or class name is by far the easiest way to navigate a project.
Others might argue that keeping things flat is better because then you don't have to keep the file system layout in sync manually and open-by-symbol plus the class browser obviate the need for stringent organisation, presenting a hierarchical relationship without the need to get either the disk or the workspace into agreement.
You first have to make the difference between folders and groups. Folders are used to organize contents on your filesystem whereas groups are used to organize contents within your Xcode project. You can think of groups as virtual folders. I personally prefer to keep a flat structure on the filesystem and organize everything using groups. This way is slightly more straight forward to include header files and it doesn't force you to maintain both the filesystem structure and the xcode structure.
In you Project you ca do any GROUPS you want to make simple and clean your project, like my screen:
Is easy and simple and you have two ways:
1) in your project right click in to right column then select NewGroup
2) drag and drop your folder in to a column to create a folder reference:
this only if you want integrate in your project a root with inside files PHP, HTML, ASP and more, but attention because after you distribute your app, if a people open .app file they found inside your REFERENCE FOLDER with all your clear code.
I think this is it ;)
Folders makes your code and its management easily, like we have packages in Java that we use to accumulate some common classes and its supporting class files.
In the same way we can use folders to manage our classes in XCode.
However its not necessary, varies from developer to developer as well as the complexity of code.
Happy Coding. :)
The approach you are discussing about is correct.
As far as folder in code is considered. If you create folder within Xcode and dividing the codes based on folders. Than all the classes will exist together on hard disk. But if you create folders within the project using finder and than adding the folder than codes will be saved to their respective folders.
Hope it will help you. Happy coding :)

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.

What is the best way for packing 6000+ sound files in a iOS Application

I'm working on a iOS application that will contain around ~6000 mp3 of sounds files.
Each one is around 1 second (2 max) long and rather low quality (24K bitrate) weighting in at around 2-3KB each. (Please do not comment on the quality, it's as it should be)
Since this is a large amount of files I was wondering what we be the best approach for packing these into the bundle? Should I just throw them together in a group? Is there someway of storing them in a single "package" file then reading them out separately as needed?
Also, what would be the best place to place them: Library/ ? Documents/?
As I'm rather new to iOS development and kick in the right direction will be greatly appreciated.
Thanks in advance,
Ken.
You can create a bundle which will contain all your mp3 files. Your files will be in the ressources of your application, no need to store them in the Documents or Library path of your application sandbox.
The way to create and access a bundle is illustrated here.
Hope this helps
There is no package type that were meant for resource files. There are ones for static and dynamic libraries, custom frameworks and so on, but purely for resources I know of none.
Instead of adding them in bulk into a Group in Xcode's project hierarchy, you should add the containing folder as a folder reference to the project. (Appears in the file navigator in blue.) This way any external modifications you make to the contents of the folder, like adding/removing files will automatically be picked up when you next compile your project.
You can do this by dragging the folder from within Finder to the project browser in Xcode and when asked choose "Create folder references for any added folders".

Resources