diff --git a/DemoProjects/NowPlayingView/NowPlayingView/ConnectionStatusIndicatorView.swift b/DemoProjects/NowPlayingView/NowPlayingView/ConnectionStatusIndicatorView.swift index 8319d41..d8a427c 100644 --- a/DemoProjects/NowPlayingView/NowPlayingView/ConnectionStatusIndicatorView.swift +++ b/DemoProjects/NowPlayingView/NowPlayingView/ConnectionStatusIndicatorView.swift @@ -14,8 +14,7 @@ class ConnectionStatusIndicatorView : UIView { self.setNeedsDisplay() if state == .connecting { if displayLink == nil { - let selector = #selector(setNeedsDisplay as () -> Void) - displayLink = CADisplayLink(target: self, selector:selector) + displayLink = CADisplayLink(target: self, selector: #selector(setNeedsDisplayProxy(_:))) } displayLink?.add(to: RunLoop.main, forMode: RunLoopMode.commonModes) } else { @@ -48,11 +47,11 @@ class ConnectionStatusIndicatorView : UIView { context.fillPath() } - fileprivate func timebasedValue() -> CGFloat { + private func timebasedValue() -> CGFloat { return CGFloat(abs(sin(Date().timeIntervalSinceReferenceDate*4))) } - fileprivate func fillColor() -> CGColor { + private func fillColor() -> CGColor { switch state { case .disconnected: return UIColor.red.cgColor @@ -62,4 +61,11 @@ class ConnectionStatusIndicatorView : UIView { return UIColor.green.cgColor } } + + // Needed because CADisplayLink(target:, selector:) + // waits for selector method having signature `(void)selector:(CADisplayLink *)sender` + // https://developer.apple.com/documentation/quartzcore/cadisplaylink/1621228-init + @objc private func setNeedsDisplayProxy(_ sender: CADisplayLink) { + setNeedsLayout() + } }