Searching Directory for items

Discussion in 'Mac Programming' started by larswik, Jan 8, 2013.

  1. macrumors 68000

    Joined:
    Sep 8, 2006
    #1
    I have a little Mac program that I wrote a while back to help me manage a small data base of graphics and info for a local grocery store. The data base has grown so large that it is hard for me to find things and the items that get sent to me become hard to look up just scanning through the directory. 1 entry might be "Wine Firestone" and another might be "Sunstone Wine". IF I look under "W" for wine I would miss sunstone.

    So I thought I would add a search bar to my program which I have never done before. My goal is to enter a search word like wine and every entry that has the word "wine" in it would be displayed.

    I was going to use NSFileManager to get a list of the items in a directory and in to an array. Then I was going to check each index to see if there is a sub string that matches the string that I am looking for. If there is a match add it to a new mutableArray. After the search display in a tableview.

    Is that about the correct process to do this?
     
  2. macrumors demi-god

    KoolStar

    Joined:
    Oct 16, 2006
    Location:
    Kentucky
    #2
    I believe that would be the most common approach. I would use the nsrange and use its range function for a string if it exist then they text contains the string you are checking for.
     
  3. ytk
    macrumors regular

    Joined:
    Jul 8, 2010
    #3
    Just make sure your comparison isn't case-sensitive. One way to do this is to convert both your search and filename strings to upper or lower case before comparison, using NSString's upperCase or lowerCase methods.
     
  4. macrumors 68040

    Joined:
    Feb 2, 2008
    #4
    Just to see if I understand, your items are files in a folder? Your program looks for a string match (the search term) to a file name?
     
  5. thread starter macrumors 68000

    Joined:
    Sep 8, 2006
    #5
    subsonix - Yes. I need a way to filter the data which will be string.
    ytk - I forgot about that, good point.
    KoolStar- Ok, so this is the approach. Objective C is so vast that I was not sure if some special class existed to do this. I was wondering if some one was going to mention a class that I was unaware of that helped it out. But it seems that this approach is the right way.

    Thanks!
     
  6. macrumors 6502a

    Sayer

    Joined:
    Jan 4, 2002
    Location:
    Austin, TX

Share This Page