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 AVAudioPlayerDelegate
protocol 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.
@interface ViewController : UIViewController <AVAudioPlayerDelegate> @end
Interestingly that didn't do it for me. I have the delegate defined in header file - working with UIImagePickerControllerDelegate in a UITableViewController. Since setDelegate method expected an id, I set delegate as follows instead:
[myImagePicker setDelegate: (id)self];
But I would like to know what's happening here ? Since this is not normally showing itself in other delegate examples in other areas of code. Could anyone elucidate on this ?
Thanks
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With