SetDelegate: self-generating caution flag

I am trying to learn Objective-C and am mistaken in the code for one of my acronyms, and I do not know how to solve it. The code:

// AppController.m #import "AppController.h" @implementation AppController - (id)init { [super init]; speechSynth = [[NSSpeechSynthesizer alloc] initWithVoice:nil]; [speechSynth setDelegate:self]; voiceList = [[NSSpeechSynthesizer availableVoices] retain]; Return self; } 

From [speechSynth setDelegate: self]; I get the error message: Sending 'AppController *' to an incompatible type parameter 'id <NSSpeechSynthesizerDelagate> ". The program compiles with a warning sign and seems to work correctly. I compared my code with the author code and I see no differences, and none of My search did not indicate that I should receive an error message on this line.The book was written for Xcode 3, and I am using Xcode 4.0.2.

Any suggestions or directions to me in the right direction would be very helpful. Thanks.

+6
source share
2 answers

Xcode warns you that the setDelegate method expects an instance of a class that implements the NSSpeechSynthesizerDelagate protocol. Now you have it, but you probably just forgot to announce that you have it. In your class declaration, change

 @class AppController : NSObject 

to

 @class AppController : NSObject<NSSpeechSynthesizerDelegate> 

to tell the world "I obey NSSpeechSynthesizerDelegate !" and keep silent the warning. You never know - you may be warned that you forgot to implement some optional delegation methods and save yourself from the annoying error somewhere in the queue.

+14
source

When you create a self object, then the warning message disappears.

 [speechSynth setDelegate:(id < NSSpeechSynthesizerDelegate >) self]; 
+2
source

Source: https://habr.com/ru/post/894769/


All Articles