[swift-users] Applying MVC pattern to iOS Swift apps
andreas at harmless.de
Fri Jun 23 12:14:22 CDT 2017
> Am 23.06.2017 um 11:41 schrieb Roy Henderson via swift-users <swift-users at swift.org>:
> Should controller functions be incorporated in the AppDelegate or is it better to keep the AppDelegate minimal and put them in a separate controller module?
You start breaking up any controller if it is getting too big. You can use extensions, you can factor out code into structures or classes or you can add additional controllers. If you decide to introduce new controllers, make sure those do only communicate with the original controller or the model.
Also, only one controller should use any one model; other controllers talk to the model's controller.
In short, models and views should be leafs in the graph, while controllers provide the structure.
> Is there any sensible demarcation point regarding which controller functions are acceptable in a ViewController? Does it make better sense to include them in the ViewController most closely associated with their actions or are they better placed in a separate module?
Well, deciding how to best organise your code is what software development is all about. There's no receipt you can follow to the letter. Just best practices and tips. So without knowing more details, it is hard to answer this question.
> In particular, I am trying to avoid breaking the rule regarding never having the V communicate directly with the M.
I'm not sure how that is related? Breaking up the controller in multiple parts doesn't change the connections to the view or the model.
If you want to continue this discussion, maybe the cocoa-dev list would be acceptable.
More information about the swift-users