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

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 :)

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.

What is the purpose of making a project in Sublime?

I was reading a blog to better understanding the purpose of making a project for sublime (or any editor):
When you save your code as a project you end up with two files. The
first is the project file which contains references to folders for
your project, project based settings and build commands for your
project. The second file is the workspace. This is simply a file that
tracks what layout you're currently using and what files you have open
in each pane. Using the workspace file means that you can switch to
another project, do some work and then switchback to your original
project knowing that the layout and files you had open will be
restored back to the state you left them in. Handy.
So seems like there's 2 reasons? 1. is to save settings and 2. is to save the current layout of the files and folders you have already opened? I see reason 2 to be nice, but not really super important. What are some of the settings in reason 1 that's important to keep in between projects? What is a build command?
You might simply have to follow different coding standards for different customers, e.g. indentation rules, so its handy that you can set these rules on a per project basis.
A build system let's you run or compile code directly from Sublime Text.

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

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?

Difference between Xcode's file adding options

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.

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