Like many people I’m interested on Objective – C and Cocoa programming. I know conceptually what a delegate it is but I don’t understand how to use them or when to use them. Here is some example code:
#import "AppControler.h"
@implementation AppControler
-(id)init
{
[super init];
NSLog(@"init");
speechSynth = [[NSSpeechSynthesizer alloc] initWithVoice:nil];
//
[speechSynth setDelegate:self];
voiceList = [[speechSynth availableVoices] retain];
return self;
}
I’m setting the AppControler to be the delegate of the speechSynthasizer. Which means that the speechSynthasizer is telling hte AppControler what to do.
But I don’t understand this line:
[speechSynth setDelegate:self];
selfis the current object, so[speechSynth setDelegate:self]sets the delegate of thespeechSynthobject to the current object, i.e. yourAppControler(sic) instance.Edit: In addition to the code shown, your
AppControlershould implement theNSSpeechSynthesizerDelegateprotocol for the messages you wish to delegate to it.