Global NSMutable array of a project - iphone

I want to know how i can declare and use a global NSMutable array of an Objective C project.
I mean i need to update the here in one class and need to use in another class....
can anyone give me any kind of idea??
Thanks
Rony

Pass a reference around from class to class. Or keep a reference to the array instance in your app delegate, which you can access from any class in your application.

You could use the singleton pattern and put the array into the singleton.

Related

Can't access global array in ARC enable project

I have define NSArray using
extern NSArray *arName;
in AppDelegate method
and then assign values in Array in AppDelegate. after assign value i easily access values in AppDelegate but when I use this global array in another page control it's shows me error
i don't know the exact problem
is it any other method to define GLOBAL ARRAY ?
You'd be better off in this case using a singleton Objective-C class. Don't use global variables with anything that is derived from NSObject, or the ARC system is unable to automatically keep track of references to the object and you'll get crashes like these.

how can i create a property for array of labels in an iphone app

In my iphone app i am programmatically creating the labels ,,i am creating array of labels
like UILabel *lblVersionName[20]; i need to copy the contents of the label into some string so i need to define property like
#property(nonatomic,retain)UILabel *lblVersionName[20];
but its giving error that "property can not have array of function type lblVersionName[20]"
cant we have property for array of labels(lblVersionName[20])
please somebody do help me, thanx in advance
Instead of C array just use NSArray or NSMutableArray
From the documentation:
Supported Types
You can declare a property for any Objective-C class, Core Foundation data type, or “plain old data” (POD) type
So you're trying to add a property for an unsupported type.
Like Terente wrote, you should use NSArray or NSMutableArray.
You might have a reason for why you need a c array, but that is only going to cause you a lot of trouble down the road. Don't fight the frameworks.

How to send All objects of Mutable Array to Another Class?

I want to send Mutable Array with all its objects from my First Class to Second Class. I have no idea how can i do this please anybody tell me the way...
Try this:
yourSecondClass.mutableArray_asAMemberVariable = [[yourFirstClass mutableArray_asAMemberVariable] copy];
This makes a copy out your firstClass mutable array and sends it to your second class.
you make one declare mutable array and make it property on other class where you want to then just give like follow
vc.nsmutablearray = the_array_you_want_to_send;

What's the best way to have functions share an array in Objective-C?

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?
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.

How to use shared array between function calls in objective C

I have one array.
I want that array to retain its value between function calls of from single class function.
I have function that is called every time page is loaded.
This function displays all the data stored in array right from application launches.
Thanks in advance.
You can store your array in appDelegate class. Or I think it will be better to make some class to store shared data and make an instance of this class in your appDelegate.