Directory structure for the new Xcode project

Let's reorganize some directories.

Default directory structure after you initialize a new project in Xcode is very simple. There is just one directory for source files and one for specs. Putting everything in one directory is a bad idea, of course you can do this, but you will be lost very soon. Also, remember that creating New group inside Xcode doesn’t correspond to creating new directory in file system. The best solution is to create a new directory inside Finder and just drag and drop it to Xcode, you will see a standard form for adding new files:

Copy new file

Uncheck Copy items if needed choose Create groups and select appropriate target. Now this new group will point to physical directory. One more thing to mention here: remember that when you put new files manually inside this directory, they will not automatically appear in Xcode project. All files have to be registered in project.pbxproj.

Now let’s create new directory structure:

|- Utils
|- Network
|- Model
|- Extensions
|- SupportingFiles
|- Modules
  - Sample Module
    - Model
    - View
    - Controller

Most of existing files will go to SupportingFiles directory, Main.storyboard and ViewController.swift will go to Modules directory. This directory will hold all files that can be identified as module, for example Register, TabBar, LatestNews etc.

The easy solution to move existing files to a different directory is to actually delete those files and add them once again from a different directory. For deleting files just choose Remove Reference instead of Move to Trash.

Remove file

Project navigator structure after changes:

Directories structure

Right now application will not compile:

Missing plist file

This is the same situation as before when we moved Info.plist for test target. Open iOSProjectStarter target and inside Build Settings look for Info.plist. Change the path to iOSProjectStarter / SupportingFiles / Info.plist. We also need to remove Info.plist from Copy Bundle Resources section otherwise it will cause a warning.

iOS doesn’t force on us any particular directory structure, which is good and bad at the same time. You have a lot of freedom, but it can sometimes lead to bad decisions. This directory is just a sample structure for MVC architecture, of course it will be different for MVVM or VIPER.

You can check actual progress on Github repository 🍪 iOSProjectStarter

In the next step we will take care of the code quality and try to improve it.