Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

larswik

macrumors 68000
Original poster
Sep 8, 2006
1,552
11
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?
 

KoolStar

macrumors demi-god
Oct 16, 2006
825
9
Kentucky
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.
 

ytk

macrumors 6502
Jul 8, 2010
252
5
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.
 

subsonix

macrumors 68040
Feb 2, 2008
3,551
79
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?
 

larswik

macrumors 68000
Original poster
Sep 8, 2006
1,552
11
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!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.