-1

I'm trying to get my head around how to do this and can't figure it out. I want to have a group of NSMutableArrays that are shared between a number of views and are used for a few different data sets that are the same. So I have one called events one called times and so on. They are used multiple times with different sets of data but the data is always of the same type.

What I want to do is to make these globally accessible but there are 2 things I'm struggling with regarding that.

  1. How do I make them globally accessible?
  2. How do I initialise them in each class so that the data can be set in that class?

Ive been looking over a few things on here and what I have at the moment is a class called Football where they are defined in a method called DefineArrays. Is this the right way to approach this problem? Then how do I call that method from another class?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Airglow
  • 71
  • 6
  • What have you tried already? I think you need to read the section of the [iOS developer guide on coordinating efforts between controllers](https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/ManagingDataFlowBetweenViewControllers/ManagingDataFlowBetweenViewControllers.html). – RyanR Aug 02 '14 at 22:50

1 Answers1

1

There are 2 ways...

  1. Create a reference class.
  2. Get access to the ViewController instance you have them declared in.
Lukas Wiklund
  • 826
  • 6
  • 21
  • This is not correct, you are just creating new instance of FirstViewController. As the name implies FirstViewController is already exist, and the array already has some objects or not does not matter, if you create same VC again array will be empty. – modusCell Aug 03 '14 at 01:12
  • @Airglow you can use a singleton class or NSNotificationCenter notifications to circulate variables. In SO there are tons of samples. For instance [this one](http://stackoverflow.com/questions/145154/what-should-my-objective-c-singleton-look-like). – modusCell Aug 03 '14 at 10:00