A
A
artem-Kolyadin2018-05-16 17:03:08
iOS
artem-Kolyadin, 2018-05-16 17:03:08

Correct architecture/model pattern for swift app?

Good afternoon.
I am making an application in Swift. An array of certain objects is loaded from the server, and I want to have access to them from different controllers in the future, or even if from one, I don’t want to reload the data. The question is how to write a model correctly (at least some kind of template or a simple but specific example), what properties and protocols to implement, how to organize the storage of this data and access to it throughout the lifetime of the application? Once I implemented the model class according to the Singleton principle, wrote sharedInstance, but it seems to me that there are more correct and appropriate pattern solutions.
PS I am familiar with design patterns, I'm not sure that they directly relate to my problem, and even if so, they describe and operate with more abstract and global entities, interaction rules, etc. But I'm interested in some specific example, for example, in which place of the controller to initialize the model object, whether to make it a property of the controller or a property of some singleton, or is everything different in general?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
briahas, 2018-05-17
@artem-Kolyadin

You make a DB controller - which: stores all data, issues data on request, saves data on request
You make a Factory - which creates all controllers (and the database too)
When creating a controller that needs to communicate with the database, the Factory, after initializing the desired controller, setapit him a database controller, and himself - if the controller also has to create something.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question