Macaret
Macaret

Reputation: 797

NSObject Class initialisation

Assume I have two UIViewControllers and a Settings (NSObject Class). And I need in both controllers some information contained in the Settings Class.

I alloc and init the Settings Class in the first controller, how can I use the same instance of the class in the second controller without allocating it again?

I know I can send the info from one controller to the other, or any other techniques, but is there a way I avoid allocing a class multiple times ?

Upvotes: 1

Views: 41

Answers (1)

Amin Negm-Awad
Amin Negm-Awad

Reputation: 16650

First of all: You do not initialize a class or a class object, but instance objects of a class.

You do not have to create new instance every time you publish information to somebody, including view controllers. Simply give both view controllers a property settingsand set the property after creation of the view controller with always the same instance of Settings.

Upvotes: 1

Related Questions