Reputation: 4486
Consider the following header file, there are 2 Delegate Protocols declaration : NSSpeechSynthesizerDelegate and NSTableViewDelegate. But after I comment off the two Delegates the program still compile and run perfectly. My question is : what is the real effect of adding the 2 delegate declaration ?
#import <Cocoa/Cocoa.h>
@interface AppController : NSObject
<NSSpeechSynthesizerDelegate, NSTableViewDelegate>
{
IBOutlet NSTextField *textField;
IBOutlet NSButton *stopButton;
IBOutlet NSButton *startButton;
IBOutlet NSTableView *tableView;
NSArray *voiceList;
NSSpeechSynthesizer *speechSynth;
}
- (IBAction) sayIt : (id) sender;
- (IBAction) stopIt : (id) sender;
- (void) speechSynthesizer : (NSSpeechSynthesizer *) sender
didFinishSpeaking : (BOOL) complete;
- (int) numberOfRowsInTableView : (NSTableView *) tv;
- (id) tableView : (NSTableView *) tv
objectValueForTableColumn : (NSTableColumn *) tableColumn
row : (int) row;
- (void) tableViewSelectionDidChange : (NSNotification *) notification;
- (void) awakeFromNib;
@end
Upvotes: 1
Views: 202
Reputation: 90117
Afaik there is only a effect for the developer, the code won't change.
If you like compiler warnings and if you are sure you implement the required methods you can live without declaring that you support the protocol.
There are no required methods in NSTableViewDelegate or NSSpeechSynthesizerDelegate, so you don't get warnings about missing functions, so it might be not so obvious.
For me these are the main reasons for using protocols:
Upvotes: 1