I just try to create singleton class that store value and use as a global. So first you need to create a Singleton-class using following code:
#import <Foundation/Foundation.h>
@interface GlobalData : NSObject
{
NSMutableArray *ClassArray;
}
+(GlobalData *) getInstance;
-(void)saveClassARray:(NSArray *)array;
-(NSMutableArray *)getGlobalArray;
@end
It's .M Class
#import "GlobalData.h"
@implementation GlobalData
static GlobalData *instanceGlobalData;
+(GlobalData *) getInstance
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
instanceGlobalData = [[GlobalData alloc] init];
instanceGlobalData->ClassArray = [[NSMutableArray alloc]init];;
});
return instanceGlobalData;
}
-(void)saveClassARray:(NSArray *)array
{
[ClassArray addObjectsFromArray:array];
}
-(NSMutableArray *)getGlobalArray
{
return ClassArray;
}
@end
Now you need to store your Students, Teachers and Parents data by following code.
First you need to import #import "GlobalData.h"
in your ViewController and create define variable that like following:
#import "GlobalData.h"
#define USERDATASINGLETON (GlobalData *)[GlobalData getInstance]
And in Web services Call back Success you need to store your data in globle array using following code:
NSArray *array =[[NSArray alloc]initWithObjects:@"Nitin",@"Nit", nil];
[USERDATASINGLETON saveClassARray:array];
Above array is just for your referance do same things for all your 3 ViewController
and store the result using saveClassARray
. now finally you need to get full array by following code:
NSMutableArray *FinalGlobalArray = [USERDATASINGLETON getGlobalArray];
NSLog(@"==%@",FinalGlobalArray);
That will be NSlog allof the data that have you stored. but make sure use some check that once you add teacher,student,parents data and if saveClassARray
calling again that old data wont be overtire that will be create duplicate entry so take care about.
Now you have finalArray you can do your search code that you have did for individual.
Hope that help