KeyboardShortcuts Documentation Beta

Structure Keyboard​Shortcuts.​Recorder

public struct Recorder: NSViewRepresentable

A SwiftUI View that lets the user record a keyboard shortcut.

You would usually put this in your preferences window.

It automatically prevents choosing a keyboard shortcut that is already taken by the system or by the app's main menu by showing a user-friendly alert to the user.

It takes care of storing the keyboard shortcut in UserDefaults for you.

import SwiftUI
import KeyboardShortcuts

struct PreferencesView: View {
	var body: some View {
		HStack {
			Text("Toggle Unicorn Mode:")
			KeyboardShortcuts.Recorder(for: .toggleUnicornMode)
		}
	}
}
KeyboardShortcuts.Recorder KeyboardShortcuts.Recorder NSViewRepresentable NSViewRepresentable KeyboardShortcuts.Recorder->NSViewRepresentable

Member Of

KeyboardShortcuts

Global keyboard shortcuts for your macOS app.

Conforms To

NSViewRepresentable

Nested Type Aliases

NSView​Type

public typealias NSViewType = RecorderCocoa

:nodoc:

Initializers

init(for:​)

public init(for name: Name)

Properties

name

let name: Name

Methods

make​NSView(context:​)

public func makeNSView(context: Context) -> NSViewType

:nodoc:

update​NSView(_:​context:​)

public func updateNSView(_ nsView: NSViewType, context: Context)

:nodoc: