Reputation: 29248
I understand that in Objective-C you declare an array in the header file and interact with it in a class. So far I'm adding things and fetching them fine within a single function. I'm new to the language however and can't figure out how to share that array across other functions.
I'd like to initialize array data in my viewDidLoad and access it from various functions later on. Is this possible and if so what's the best way to do it?
Upvotes: 1
Views: 169
Reputation: 96966
Like you said, declare the array in the view controller's header file and make it a @property
. Use alloc-init in the implementation's -viewDidLoad
method to set it up. Deallocate it in the dealloc
method. Use its property setter (self.array
) to retain or assign another array, depending on the @property
attribute. Access it directly (array
) throughout your methods in your class implementation, and via its property getter (obj.array
) from other classes.
Upvotes: 4