0

I am sorry to ask this but I have searched for hours on doing this but I really don't understand it. Please help me. I have a .plist file in my Xcode project and it's root is a Dictionary type. It contains about 50 more dictionaries. Inside the dictionary contains strings. (Dictionary(root) > Dictionary > String. I added a search field to my toolbar and linked it to my code. I am able to get what the user types but then how do I "search" after getting what the user typed? Is there a method for this and how do I link it into my .plist? Thank you so much!!!

user1927992
  • 123
  • 1
  • 7
  • 1
    you can do it easily with almost no-code using binding. – Anoop Vaidya Mar 05 '13 at 12:29
  • Is it able to link it to a plist or a dictionary? Can you teach me how to do that? Thanks! – user1927992 Mar 05 '13 at 12:50
  • 1
    NSSearchField can be linked to an array or dictionary not to plist file. And searching sorting filerting etc all can be done without a single line of code!!! I cant teach but you can learn yourself online :) If you stuck then I will try to help you out. – Anoop Vaidya Mar 05 '13 at 12:53
  • Thank you so much!! I appreciate it very very much! Since that you know about this, can you give me any suitable website for me to learn on this? (I am asking from you since you will know this better than me) Thank you in advance!!! – user1927992 Mar 05 '13 at 13:43
  • 1
    http://cocoadevcentral.com/articles/000080.php – Anoop Vaidya Mar 05 '13 at 13:51
  • 1
    This is my answer here, you will get some help from http://stackoverflow.com/questions/14562633/binding-search-field-and-table-view-in-cocoa/14562958#14562958 – Anoop Vaidya Mar 05 '13 at 13:57

1 Answers1

1

You want to search for the user entered string in your Dictionary of Dictionaries?

You're going to have to iterate each dictionary, asking [dict objectForKey:userEntry] in each. Not sure if you want to only find first match or all matches too.

Additionally, you may want to create an abstraction of your Dictionary of Dictionaries to reduce the scale of the problem and clarify the API. In simpler terms, wrap your Dictionary of Dictionaries in a class and put a sensible (non-dictionary-based) set of methods on it. It's probably worth the effort.

To load the plist into a Dictionary, look at [Dictionary dictionaryWithContentsOfFile].

Edit: Filtering options on NSDictionary

Have you looked at the following options for filtering values in an NSDictionary:

Community
  • 1
  • 1
wmorrison365
  • 5,995
  • 2
  • 27
  • 40