I am trying to create a global array in my app which can be accessed by ALL view controllers. I have put the code in the AppDelegate and then imported the AppDelegate in to the view controller files.
Within the app delegate, I have created an array in the didFinishLaunchingWithOptions:
function. However, I need to create a new function in the AppDelegate which I can then call from other view controllers to filter this global array. So far I have this:
// Function to get suggested foods
- (BOOL)getFood:inCategory(NSString *)foodCat
{
NSMutableArray *filteredArray=[[foodArrayMain filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"(foodCat==%@)",foodCat]] mutableCopy];
return filteredArray;
}
However, I know there are errors here and it doesn't seem to work. I have tried calling it in one of the other view controllers like this:
NSArray *foods= [AppDelegate getFood:@"meats"];
Any help?