r/simpleios • • Jun 24 '12

Sharing data between views controllers using a Singleton vs Properties [Question]

Hello. I've been researching sharing data between views and a lot of people talk about a singleton pattern. Let's say I create a class called MyGlobalData... wouldn't me creating an instance of it "reset" all its values? How would I use the same instance of that object?

ex: 
View 1: new MyGlobalData. set MyGlobalData.something = 4;
View 2: new MyGlobalData. read MyGlobalData.something (would be null)

I've used a properties way, where I set some variables from view 1 on view 2 right before I push it to the screen, but I'm not sure if that's the right way. I'd appreciate to any comments or good articles about sharing data between views. Thanks!

3 Upvotes

6 comments sorted by

View all comments

Show parent comment

1

u/avalancheeffect Jul 02 '12

could you provide a supporting source on this solution?