The following code gave a warning of Sending 'ViewController *const __strong' to parameter of incompatible type 'id<AVAudioPlayerDelegate>' (it is the third line in the following code):
NSURL *sound0URL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"0" ofType:@"aiff"]];
audioPlayer0 = [[AVAudioPlayer alloc] initWithContentsOfURL:sound0URL error:nil];
[audioPlayer0 setDelegate: self]; // <--- this line causes the warning
[audioPlayer0 prepareToPlay];
audioPlayer0.currentTime = 0;
[audioPlayer0 play];
How can it be fixed? I have this code in the ViewController‘s instance method of viewDidLoad. There was another question similar but that was a class method: Incompatible pointer types assigning to 'id<AVAudioPlayerDelegate>' from 'Class'
Conform to the
AVAudioPlayerDelegateprotocol in your header file and the warning will go away. By not declaring that a class conforms to a given protocol, the compiler cannot guarantee (well, at least warn) about your failure to implement the methods required of it. The following code is a corrected version that will suppress the warning.