class myClass: AVAudioPlayerDelegate{
var player = AVAudioPlayer()
init(){
player.delegate = self
}
func audioPlayerDidFinishPlaying(_ player: AVAudioPlayer, successfully flag: Bool) {
print("The song ended")
}
}
我正在学习Swift并试图制作一个音乐播放应用程序。我有自定义类,其AVAudioPlayer对象称为播放器作为其属性。我怎样才能用AVAudioPlayerDelegate
方法与玩家对象?Swift如何在不继承AVAudioPlayer的类上使用AVAudioPlayerDelegate?
当具有这样的代码我得到的错误:
从NSObject的The type myClass does not conform to the protocol NSObjectProtocol
的可能的复制[等级不符合NSObjectProtocol(https://stackoverflow.com/questions/40705591/class-does-not-conform-nsobjectprotocol) –