2

I been reading about avoiding the mutable state, and how the singleton pattern is bad for having a global state.

I see few answers about Dependency injection http://www.objc.io/issue-13/singletons.html, but I can not find how to solve this basic approach:

How maintain the user data arround the app?, the solution is to pass the user information from the one view (where is requested by webservice) through the views by parameter to the seven push view (where is needed again) ?

there is a better way?, or the singleton pattern is sometimes necessary?

Paulw11
  • 108,386
  • 14
  • 159
  • 186

1 Answers1

0

I use a singleton to represent my Engine class in Swift. It is initialized once on launch and contains static class variables stored in a struct. Works fine for me.

class Engine{

struct properties{

static var resourceManager:ResourceManager!;
...
}

init(){
properties.resourceManager = ResourceManager();
}

In another class I can then call

Engine.properties.resourceManager

NJGUY
  • 2,045
  • 3
  • 23
  • 43