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/cubedgame Jul 21 '12

In the DetailViewController's viewDidLoad method, you would use that information like so:

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.title = self.name;
    
    // Set other data structures or objects with the other properties that were set
}