Best practice for an Xcode project groups structure?

AppsDev picture AppsDev · Oct 9, 2016 · Viewed 23k times · Source

In tutorials and examples that provide code samples, sometimes I see that project files in the Xcode's Project navigator are arranged by groups following the MVC pattern ("Views", "Controllers", "Model"), and other times they are organized into groups by functionality ("Login", "Checklist", for instance).

Concerning iOS, is there any Apple's convention/recommendation for this? Which should be the best practice?

Answer

Jamshed Alam picture Jamshed Alam · Oct 9, 2016

Developers organise their groups, code, and files many ways. But I use something like the following:

  • CoreData: Contains DataModel and Entity Classes.

  • Extension: Contain One class(default apple class extensions+project class extensions.)

  • Helper: Contain Third Party classes/Frameworks (eg. SWRevealController) + Bridging classes (eg. Obj C class in Swift based project)

  • Model: Make a singleton class (eg.AppModel - NSArray,NSDictionary, String etc.) for saving data. The Web Service Response parsing and storing data is also done here.

  • Services: Contain Web Service processes (eg. Login Verification, HTTP Request/Response)

  • View: Contain storyboard, LaunchScreen.XIB and View Classes. Make a sub folder Cells - contain UITableViewCell, UICollectionViewCell etc.

  • Controller: Contain Logic or Code related to UIElements (eg. UIButton’s reference+ clicked action) It could be replaced by ViewModel if MVVM is employed.

This structure is from another Stack Overflow post.

These may also help you:

  1. http://akosma.com/2009/07/28/code-organization-in-xcode-projects/

  2. https://github.com/futurice/ios-good-practices/issues/28

  3. http://www.slideshare.net/MassimoOliviero/architecting-ios-project