以下代码给出了警告Sending 'ViewController *const __strong' to parameter of incompatible type 'id<AVAudioPlayerDelegate>'
(它是以下代码中的第三行):
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];
如何修复?我在ViewController
的实例方法中有这段代码viewDidLoad
。还有另一个类似的问题,但那是一个类方法:Incompatible pointer types assignmenting to 'id<AVAudioPlayerDelegate>' from 'Class'