Searching

Searching

The final feature of your sample app is to implement some search functionality. You are going to filter the list tasks according to their Objective. With the DADataTableController, this is really simple to do. The whole search will happen on the client.

The Main Form

Add a new Search field directly to the toolbar. Name it Search and connect a new IBAction method called filterAction to the AppDelegate outlet.

AppDelegate

In the AppDelegate.m file, implement the filterAction method.

- (IBAction)filterAction:(id)sender {
 
    NSSearchField *sf = (NSSearchField *)sender;
    NSString *pattern = sf.stringValue;
 
    NSPredicate *condition = nil;
 
    if (pattern.length > 0) {
        condition = [NSPredicate predicateWithFormat:@"(Task contains[cd] %@)", pattern];
    }
    [self.tableController setFilterPredicate:condition];
}

Implementing the filter was a simple as setting a predicate on the DADataTableController.