How to Organize Code Files in iOS

File structure is an ever changing spec based on many factors like team size, design pattern, and overall team input. This living document is designed to act as a starting point for exiting and new projects. This will ensure a form of consistency between applications, and ensure smooth management of the project over time.

Feature based folders structure

A feature based folder structure, using MVVM+C, is very similar to using the typical structure that you see in most apps. The key difference being you keep feature based information together.

A typical app most often will typically express their folder as outlined below.

Folder-by-type disadvantages include the following

  • You are forced to jump around folders when creating a feature.
  • You end up with a very large single vertical tree of information, since it lives in the main directory of the project.
  • Removing the feature requires you to be lead by the compiler because references to other types are often spread vastly across the project.
  • Leads to more merge conflicts if you ever want to reorder files

Folder-by-type include the following

  • Very easy to get setup with a small team
  • Typically easier to follow if there are a low number of features

A feature file structure can be expressed like so. The major difference being every feature has the following folders.

Folder-by-feature cons include the following,

  • Typically takes members a little longer to become familiar with.
  • Often requires a little ramp up period to get added to an already existing project.
  • It can be harder to learn what already exists in the app, sometime resulting in duplicate code

Folder-by-feature Pros include the following

  • Easier for larger teams to maintain
  • Easier to remove features when the time comes

The below expresses what this could look like within your app. If it is a file that should be shared with the rest of the app, they should live in the shared directory.

For free consultation on how to organize code files in iOS, click here.

WRITTEN BY

Deimante Boguzaite

2024-04-23

Get a FREE quote
All In One Place For Your Business Growth And Success

We have built partnerships for a decade. Collaborate with Utah Tech Labs to build trust together.