Contact

Technology

Jun 13, 2018

Organizing an iOS Project

Zachary Slayter

Zachary Slayter

Organizing an iOS Project

When I first learned iOS development, no one taught file organization. I went through many tutorials and learned how to program in Swift, use storyboards and constraints, and other basic skills to get started in iOS. However, these resources didn’t provide any recommendations for file organization and left me unprepared to work in a full enterprise application. Now, after working on multiple iOS projects, I have developed a basic file structure that I use to make the application easier to grasp.

This blog post will walk you through the different directories and the purpose of each one. This approach is a great starting point to get your application off the ground, but remember to tailor it to your specific needs.

The organization in the root project folder consists of the following folders:

  • App

  • Constants

  • Components

  • Extensions

  • Resources

  • Storyboard

  • Models

  • API

App

This folder contains two files in a basic iOS project: “AppDelegate.swift” and “Info.plist”. These files affect the entire app, and are referenced many times throughout development. I place this folder at the top of the root folder to ensure that these files are always easy to find. This folder can also hold configuration files and files that are global to the entire app.

Constants

This folder contains a base “Constants.swift” file, along with other “Constants_{feature}.swift” files that are used to keep the constants organized. The way this works is that the “Constants.swift” folder holds the class “Constants” and contains any constants that are used app-wide. The other files could include things like “Constants_Error.swift”. This file would be an extension to the “Constants” class, and include things like error codes. By using the extension feature in Swift, you can keep your constants organized in different files, and still be able to call “Constants.ErrorCodes” throughout your application.

Components

This folder contains any reusable components that your application might need. This could include something like a “BaseViewController.swift” file that extends “ViewController” and gives all your view controllers some custom base functionality. Depending on how many reusable components you have, this folder might need further organization.

Extensions

This folder holds extensions for built-in Swift classes. A file you might find in this folder would be “String.swift”, which would include functions to improve the “String” class, such as a “contains(s: String) -> Bool” function that would return true if a string contains another string. Many useful extensions for common Swift classes can be found with some quick Googling.

Resources

This folder contains the “Assets.xcassets” file. Usually that is the only thing contained in this folder as it holds all your images, however if you have any other resources for your project that can’t be added to the assets, then they should go in this folder.

Storyboard

This folder contains folders for the different flows in your app. For a basic app, this folder could contain the following folders:

  • LaunchScreen

  • Main

  • Home

  • Login

  • Register

Launch Screen

This folder contains “LaunchScreen.storyboard”, which is used to create the screen shown when launching the app.

Main

This folder contains the main storyboard and view controller, which will most likely be used to set up your TabBarController and redirect to other storyboards, if necessary.

Home, Login, Register, etc.

These folders contain the storyboard files and view files responsible for displaying and controlling these different flows. The structure of these folders will vary greatly depending on the complexity of the flow.

Models

This folder contains any models that your app or API will require. If you have a large number of models, then you will need to implement an organization strategy for this folder as well. If you ever access elements in an object directly using JSON or XML, stop and consider creating a model for the object. They will keep your code clean and maintainable.

API

This folder will contain any code used to communicate with outside APIs. Also, consider having some base classes in here to take care of boilerplate code that is usually necessary when working with APIs.

The Value of Organization

This file structure will give you a clean and organized starting point for your iOS application. As your projects grow, you will need to add more organization in certain sections to keep the structure understandable, but it is worth the effort. The code may run the same with or without great organization, but with it, your projects will be easier for other developers to pick up, and you will be able to maintain your sanity a little bit longer.

In conclusion, next time you find yourself in need of organization for an iOS project, give this structure a try. It has helped me out with my projects, and it can help you too. Feel free to reach out with any questions by emailing us at findoutmore@credera.com.

Conversation Icon

Contact Us

Ready to achieve your vision? We're here to help.

We'd love to start a conversation. Fill out the form and we'll connect you with the right person.

Searching for a new career?

View job openings