The right way to architect a filter for the iPhone?
<p>I'm not proud of this, but this is the current design of our program.  </p>

<p>I have a filter object that looks pretty much like this:</p>

<pre><code>#import "Filter.h"

@implementation Filter

@synthesize DataSet = _dataSet;
@synthesize FilterList = _filterList;
@synthesize TypeOfFilter = _typeOfFilter;
@synthesize isFilterOn;

- (id)initWithDataSet:(NSArray *)array {
    self = [super init];
    if (self) {
        if ([array count] &gt; 0) {
            self.DataSet = array;
            [self CreateFilterList];
        }
    }
    return self;
}

- (void)CreateFilterList {
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithCapacity:[_dataSet count]];
    for (NSString *str in _dataSet) {
        if (![str isEqualToString:@"NULL"]) {
            [dict setObject:[NSNumber numberWithBool:NO] forKey:str];
        }
    }
    self.FilterList = dict;
    [dict release];
}

- (BOOL)isFilterOn {
    NSArray *filters = [_filterList allKeysForObject:[NSNumber numberWithBool:YES]];
    if ([filters count] &gt; 0) {
        return YES;
    }
    else {
        return NO;
    }
}

- (NSArray *)GetCurrentFilters {
    return [_filterList allKeysForObject:[NSNumber numberWithBool:YES]];
}

- (void)ResetFilter {
    for (NSString *key in [_filterList allKeys]) {
        [_filterList setObject:[NSNumber numberWithBool:NO] forKey:key];
    }
}

@end
</code></pre>

<p>So in our model, we basically create a TypeOfFilter for something we want to filter on.  For example, we can create a @"Name" filter to filter on Name in our database.  All the Filter objects are members of our model class.  I didn't really know of another way to do this at the time and I'm looking at how to refactor for the future.  Essentially my filter is just a dictionary whose value is YES for items that we want filtered on.  </p>

<p>In our MainViewController, we present the user with the option to filter on different things like Name in a popover.  When a selection is made, the Filter object is updated by something like this:</p>

<pre><code>    [((Filter *)[modelClass.FilterDictionary objectForKey:@"NameFilter"]).FilterList setObject:[NSNumber numberWithBool:YES] forKey:key];
</code></pre>

<p>In our modelClass, there is a Dictionary of Filter objects.  So based on the user's selection, we get the appropriate Filter object by the name, and set YES or NO based on their selection.  </p>

<p>Also when a selection is made in the popover that presents the options to the user to filter on, an action is made to a DoFilter method that basically redraws the MainViewController's content with the appropriate items.</p>

<p>I personally hate this design and was wondering the different ways I can improve on it.  Thank you.</p>
