Learn-iOS-Swift-by-Examples/MPRemoteCommandSample/MPRemoteCommandSample-macOS/RemoteCommandView.swift

39 lines
1.3 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
Copyright (C) 2016 Apple Inc. All Rights Reserved.
See LICENSE.txt for this samples licensing information
Abstract:
`RemoteCommandView` is a `NSView` subclass that responds to the user toggling a specific `MPRemoteCommand` as enabled/disabled.
*/
import Cocoa
class RemoteCommandView: NSView {
// MARK: Types
/// The reuse identifier to use for retrieving this view.
static let reuseIdentifier = "RemoteCommandViewIdentifier"
// MARK: Properties
/// The `NSButton` that is used for toggling an `MPRemoteCommand` as enabled or disabled.
@IBOutlet weak var button: NSButton!
/// The delegate that is used to respond to target-action calls.
var delegate: RemoteCommandViewDelegate?
// MARK: Target-Action
@IBAction func userDidToggleCheckButton(_ sender: NSButton) {
delegate?.remoteCommandView(self, didToggleTo: sender.state == NSOffState ? false : true)
}
}
/// `RemoteCommandViewDelegate` provides a common interface for `RemoteCommandView` to provide callbacks to its `delegate`.
protocol RemoteCommandViewDelegate {
/// This is called when the `NSButton` in a `RemoteCommandView` is clicked to reflect a change in state.
func remoteCommandView(_ cell: RemoteCommandView, didToggleTo enabled: Bool)
}