I'm attempting to use CADisplayLink to update a UIProgressView. Here's CADisplayLink's initialiation signature
Here's a summary of the relevant variables from MyAudioPlayer class.
protocol AudioPlayerDelegate: class {
func updateSlider(sender: AudioPlayer)
}
class AudioPlayer: NSObject {
// relevant vars
var updater: CADisplayLink?
weak var delegate: AudioPlayerDelegate?
func play() {
// some setup stuff
updater = CADisplayLink(target: self, selector: #selector(delegate?.updateSlider(sender:)))
// regular stuff to play an audio file
}
}
When I initialize updater in the play() method, the compiler says, :
Argument of
#selectorrefers to instance methodupdateSlider(sender:)that is no exposed to Objective-C.
Easy enough...add objc in front of func updateSlider(sender: AudioPlayer), like so:
@objc func updateSlider(sender: AudioPlayer)
The compiler error goes away for a nanosecond, then the the line I just updated says:
@objc can only be used with members of classes, @objc protocols, and concrete extensions of classes.
There are a few answers covering this topic, but I haven't found one that works.
I tried throwing updateSlider in an extension instead of in the protocol section, but I keep getting this ping pong of the compiler wanting to add @objc in front followed by wanting to remove it.
I also attempted to use an instance of the Timer class instead of the CADisplayLink class to do this, but I encounter the same issue.
Thank you for reading. I welcome your suggestions.