lundi 2 janvier 2017

MVC: Where to store data?

I like to apply the Model-View-Controller design pattern in a Cocoa application (written in Swift). Let us assume the famous person example: the App should show a text field and an add button. A persons name can be put into the text field and then be stored in an array by clicking the add button (and the arrays content may be shown in a table view). Now, the storyboard contains all my View-related stuff while a class Person (with a variable name) constitutes the Model-class. The view controller would be responsible for receiving an showing the data (table view delegate and data source for example) and has an IBAction which extracts the name and puts it somewhere. But, I am not sure where to actually put the array that holds all the names. Would I have it in the view controller as well (which would be the most easiest solution I think)? Or somewhere else? What if the App becomes more and more elaborate with multiple data holding structures in different views (with different view controllers)?

Aucun commentaire:

Enregistrer un commentaire