Search on Arrays inside Plist in Xcode

I’m developing an app that should search a string inside the Plist data and return a value that should prompt the user what kind of, say brand it is. For example, the user inputs “iPhone” in my text field and the app should return the brand of the product the user inputted after tapping the Go button below the text field.

Inside my Products.plist, It contains arrays of brands with certain products that brand has. Example would be:

  • UIPageViewController and removing current view controller
  • Retain cycle when grabing values or keys from Dictionary in Swift
  • How to stretch Image to fill the Label Width set in Background in UILabel?
  • Actual difference between UIAccessibilityLayoutChangedNotification and UIAccessibilityScreenChangedNotification?
  • Would mutating an ArraySlice instantiate a new array instance?
  • HTML file input control with capture and accept attributes works wrong?
  • Apple: iPhone, iPod, iPad, Mac
    Sony: PSP, PS3, Bravia, Xperia
    Samsung: Galaxy S II, Galaxy S III, Galaxy Tab

    How can I do this? I have already done my app working fine but without using a plist. I just want to use a Plist for the app to be easily maintained and updated.

    Solutions Collect From Internet About “Search on Arrays inside Plist in Xcode”

    Consider your plist file is called data.plist, this is how you should do this:

    NSBundle *bundle = [NSBundle mainBundle];    
    NSString *pListpath = [bundle pathForResource:@"data" ofType:@"plist"];
    NSDictionary *dictionary = [[NSDictionary alloc] initWithContentsOfFile:pListpath];
    
    for (NSString* key in [dictionary allKeys]){
        NSArray *array = [dictionary objectForKey:key];
        for (int j = 0; j < [array count]; j++) {
            if ([[array objectAtIndex:j] isEqualToString:@"iPhone"]) {
                NSLog(@"%@",key);
            }
        }
    }