Reputation: 797
Assume I have two UIViewController
s 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
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 settings
and set the property after creation of the view controller with always the same instance of Settings
.
Upvotes: 1