O'Reilly logo

Beginning Mac OS® X Programming by Drew McCormack, Michael Trent

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

A.13. Chapter 13

A.13.1. Exercise solution

  1. Open the Searcher project in Xcode, and select the Searcher.h file in the Groups & Files panel, such that it appears in the editor. Make the highlighted changes in the following code:

    #import <Cocoa/Cocoa.h>
    
    @interface Searcher : NSObject
    {
        IBOutlet NSArrayController *pathsController;
        NSArray *paths;
        NSString *rootDirectoryPath;
        NSString *nameContainsString;
        int searchingState;
        NSTask *task;
    }
    
    -(IBAction)openFile:(id)sender;
    -(IBAction)showInFinder:(id)sender;
    -(IBAction)toggleSearch:(id)sender;
    
    -(NSArray *)paths;
    -(void)setPaths:(NSArray *)paths;
    
    -(NSString *)rootDirectoryPath;
    -(void)setRootDirectoryPath:(NSString *)path;
    
    -(NSString *)nameContainsString;
    -(void)setNameContainsString:(NSString *)str;
    
    -(NSTask *)task;
    -(void)setTask:(NSTask *)task;
    
    -(int)searchingState;
    -(void)setSearchingState:(int)newState;
    
    @end
  2. Open the Searcher.m file in the editor and change the init and dealloc methods as follows:

    -(id)init { if ( self = [super init] ) { [self setPaths:[NSArray array]]; [self setRootDirectoryPath:NSHomeDirectory()]; [self setNameContainsString:@""]; [self setSearchingState:NSOffState]; [self setTask:nil]; // Register for NSTask termination notifications [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(taskDidTerminate:) name:NSTaskDidTerminateNotification object:nil]; } return self; } -(void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; [paths release]; [rootDirectoryPath release]; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required