Reputation: 841
For some reason I am having a bit of confusion about how to go about getting my XML Parser to parse a document when the app first starts and then initialise an array that will be ready to pick up at any time on another class in my app.
So lets say in the first ViewController we call my XML parsing class, it parses the XML and packs everything into an array. How do I then make that array available to another class at anytime without recalling the XML parsing class?
Any ideas?
PS:
I know its a stupid and ignorant question. I know theres probably something similar but I wanna make sure I learn the best way to do this kind of a thing.
Upvotes: 0
Views: 475
Reputation: 1616
There are many ways for passing the one array from one class to other.One simple way I have explained below.I hope it will help you.
In your app delegate file declare one NSMutableArray variable.
//in appdelegate.h file
NSMutableArray *arrDataArray;
//Now declare property for it
@property (nonatomic,strong)NSMutableArray *arrDataArray;
//synthesize the array instance in appdelegate .m file
@synthesize arrDataArray;
//Now in the view controller in which you are doing the parsing in that declare shared instance of app delegate file as below
AppDelegate *objAppDel = (AppDelegate*)[[UIApplication sharedApplication] delegate];
Now save the parsed result in arrDataArray.So objAppDel.arrDataArray holds your parsing result.If you want to access the arrDataArray in other viewcontroller class then again declare shared instance of appdelegate file & access the arrDataArray as objAppDel.arrDataArray.
Upvotes: 1