mardi 29 août 2017

Xcode MVC pattern - where to put the code - how you do it

I do have a simple Xcode project and have structured it like this:

myProject
--Storyboards
----LaunchScreen.storyboard
----Tutorial
-------Tutorial.storyboard
-------TutorialFeature.xib
--Data
----Tutorial
-------TutorialData.plist
---Model
-----Tutorial
-------TutorialModel.swift
--View
----Tutorial
-------TutorialFeature.swift
--Controller
----Tutorial
-------TutorialController.swift

According to the MVC pattern rules (feel free to correct me when I'm wrong):

  • the Model deals with the Data
  • the Controller deals with the Model, business logic and passes everything to the View
  • the View displays it all

I'm dealing with a NIB which is loaded by the View and populated with Data from the Model by the Controller. In the example above:

  • TutorialFeature (View) -> loads: TutorialFeature.xib
  • TutorialController loads Data from TutorialModel and passes it to the View

However, I've seen many examples where the NIB is loaded and populated with Data in the Controller, leaving the View with just the Outlets.

What's the best practice from your point of view and am I wrong to load the NIB from the View as it can be seen as business logic, no?

Aucun commentaire:

Enregistrer un commentaire