0

What is the preferred method for inter-class communications? If one of my classes needs to access a value that's coming from another class should I use the App Delegate as a sort of Central Hub or is it better to #import them directly?

What's the cleaner/better route to take?

KDM
  • 197
  • 5
  • 18
  • Related: [passing data in the init](http://stackoverflow.com/a/7791328/412916), using [a singleton as a hub](http://stackoverflow.com/a/7594230/412916), using one of the [storage options](http://stackoverflow.com/a/6391408/412916). Sharing data between view controllers has been asked a few times, you'll find more answers through the search box. – Jano Jan 11 '12 at 16:55

2 Answers2

1

I use iVars and class methods to achieve what you want, the AppDelegate should not be a boiler for sharing variable between classes. But you can.

Mat
  • 7,613
  • 4
  • 40
  • 56
0

There are several ways to solve it:

  1. Import one class to another and use its methods/properties.
  2. Create a global class, initialize it with some values. Access to this class from all another required classes. See http://en.wikipedia.org/wiki/Singleton_pattern
  3. NSNotification - see NSNotificationCenter Class Reference. It allows you to execute some code in your current class when another class execute its own code or fires some action.
beryllium
  • 29,669
  • 15
  • 106
  • 125