Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6061077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:53:50+00:00 2026-05-23T08:53:50+00:00

I have a data-structure (in plist) that looks something like this: What i have

  • 0

I have a data-structure (in plist) that looks something like this:

enter image description here

What i have here is an NSArray of NSDictionary. Each NSDictionary has two keys:

Title
Link (recursive)

This forms a tree like structure, with variable length branches i.e. some branches can die at level 0, and some can be as large as level 3 or more.

I’m showing this structure in UITableView (with a little help from UINavigationController). This was easy enough.

Note: On tapping the Leaf Node
(represented by NSDictionary object
with Nil or Zero as “Link”), an
event is triggered i.e. Model window
appears with some information.

Now, i need to add Search support.

Search bar will appear above UITabeView (for Level 0). I need to come-up with a way to search this tree like structure, and then show the results using UISearchDisplayController, and then allow users to navigate the results as well.

How?… is where i’m a little stuck
and need some advise.

The search has to be quick, because we want search as you type.

p.s. I’ve thought of translating this data structure to CoreData, and it’s still lurking in my mind. If you think it can help in this case, please advise.


Edit:
Here’s my current solution, which is working (by the way):

#pragma mark -
#pragma mark UISearchDisplayController methods 

- (void)searchBarResultsListButtonClicked:(UISearchBar *)searchBar {
    NSLog(@"%s", __FUNCTION__);
}

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString {
    NSLog(@"%s", __FUNCTION__);
    [self filterCategoriesForSearchText:searchString
                               scope:[controller.searchBar selectedScopeButtonIndex]];

    // Return YES to cause the search result table view to be reloaded.
    return YES;
}

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption {
    NSLog(@"%s", __FUNCTION__);
    [self filterCategoriesForSearchText:[controller.searchBar text]
                               scope:[controller.searchBar selectedScopeButtonIndex]];

    // Return YES to cause the search result table view to be reloaded.
    return YES;
}

#pragma mark UISearchDisplayController helper methods

- (void)filterCategoriesForSearchText:(NSString *)searchText scope:(NSInteger)scope {
    self.filteredCategories = [self filterCategoriesInArray:_categories forSearchText:searchText];

    NSSortDescriptor *descriptor = [[[NSSortDescriptor alloc] initWithKey:KEY_DICTIONARY_TITLE ascending:YES] autorelease];
    [self.filteredCategories sortUsingDescriptors:[NSArray arrayWithObjects:descriptor, nil]];
}

- (NSMutableArray *)filterCategoriesInArray:(NSArray *)array forSearchText:(NSString *)searchText {
    NSMutableArray *resultArray = [NSMutableArray array];
    NSArray *filteredResults = nil;

    // Apply filter to array
    // For some weird reason this is not working. Any guesses? [NSPredicate predicateWithFormat:@"%@ CONTAINS[cd] %@", KEY_DICTIONARY_TITLE, searchText];
    NSPredicate *filter = [NSPredicate predicateWithFormat:@"Title CONTAINS[cd] %@", searchText];
    filteredResults = [array filteredArrayUsingPredicate:filter];

    // Store the filtered results (1)
    if ((filteredResults != nil) && ([filteredResults count] > 0)) {
        [resultArray addObjectsFromArray:filteredResults];
    }

    // Loop on related records to find the matching results
    for (NSDictionary *dictionayObject in array) {
        NSArray *innerCategories = [dictionayObject objectForKey:KEY_DICTIONARY_LINK];

        if ((innerCategories != nil) && ([innerCategories count] > 0)) {
            filteredResults = [self filterCategoriesInArray:innerCategories forSearchText:searchText];

            // Store the filtered results (2)
            if ((filteredResults != nil) && ([filteredResults count] > 0)) {
                [resultArray addObjectsFromArray:filteredResults];
            }
        }
    }

    return resultArray;
}
  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:53:51+00:00Added an answer on May 23, 2026 at 8:53 am

    Core Data would be able to perform the search in the data store pretty efficiently, and would scale the search to more levels efficiently. Also, if you use NSFetchedResultsController for the TableView it would almost certainly be more memory efficient – the worst case would only have one level array loaded at any given time. And the best case is considerably better, as it would only have faulted a few objects into the array. HTH

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data structure that looks like this: @results['events'].each do |event| event.inspect end
I have a data structure that looks like this: data =[ {'key_1': { 'calc1':
I have a data structure (created from a YAML document) that looks like this:
I have a data structure that looks like this: [ {:choices=>[Hello, Hi]}, , {:choices=>[wor,
I have a data structure that looks like this: public class Node { public
Using EF4 and Linq I have a data structure which looks like this: parentid
I have a data structure that represents C# code like this: class Namespace: string
I have a data-structure which is something like this: The population of three cities
I have a data structure something like this: typedef struct tagSUB_DATA { double measuredValue;
I have a data structure in my C++ program that has some attributes of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.