Access to a model object from multiple controllers?

I have an application that uses the UITabBarController to install two other controllers that need access to the same model object. Can anyone give me any information on how to best implement this. My initial thought was to use a singleton with which I could access, and I wonder if I am missing a better method?

+3
source share
1 answer

I usually create my model as a singleton. This brings convenience, but can also tempt access to it from views that violate the MVC paradigm. Passing a model to each controller is probably a safer way.

You can find helpful tips for creating objective-C singleons in this article.

I saw some developers put it as a property on applicationDelegate, but the model definitely does not belong.

I will vote for singleton!

+2
source

Source: https://habr.com/ru/post/1778702/


All Articles