for iOS 5.0 using ARC, here is something I want to implement and need direction on how it can be best done. I have some global settings that determine the state of each object in the object tree. I need this to be just one instance shared by all objects and their children so that on changing the settings, the behaviour of these objects change as well… to make it clear, its something like this..
Global Settings (current language)
|(should affect)
----------------------------
| |
GenericParent1 GenericParent2
| |
------------
| |
ChildType1 ChildType2
While borrden answer is correct, (singletons are used in case you want to make sure you have only one instance runing) the implementation should be something like this:
So that you can take advantage of the grand central dispatch.
You can read more about this here: http://cocoasamurai.blogspot.jp/2011/04/singletons-your-doing-them-wrong.html
Edit:
With static implementation, do you mean something like global variables? If i understand correctly you want to “share” a state between 2 or more instances that come from the same parent. However each instance has its own local variables and those inherited, but still the inherited ones are specific for THAT instance. If you want to share a state between these objects you need something global to communicate. For example, if you want to share an object between 2 instances you have to make their pointers point to the same object, then you can read the “state” saved in that object for both and if you change it from one place it will change from the other. The problem with this is that you cannot ensure you will only have one instance of that object. You might even by mistake create more than one and be accessing a different one on your methods. This is what a singleton solves, even if you try creating a new one you will just get the original.
Alternatively you can have a global variable and share information trough that. but that approach is not very well looked upon, because it makes your code a little hard to understand sometimes.