Skip to content

Commit 6395c6d

Browse files
committed
Add Shortcut#toSwiftUI as public API
Closes #230
1 parent 5e508ab commit 6395c6d

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

Sources/KeyboardShortcuts/Shortcut.swift

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,9 +752,23 @@ extension KeyboardShortcuts.Shortcut: CustomStringConvertible {
752752
}
753753

754754
extension KeyboardShortcuts.Shortcut {
755+
/**
756+
Converts this shortcut to a SwiftUI `KeyboardShortcut`.
757+
758+
Use this to apply a user-defined shortcut to a SwiftUI view using the `.keyboardShortcut(_:)` modifier.
759+
760+
Returns `nil` if the shortcut cannot be represented in SwiftUI (for example, certain special keys).
761+
762+
```swift
763+
Button("Perform Action") {
764+
performAction()
765+
}
766+
.keyboardShortcut(shortcut.toSwiftUI)
767+
```
768+
*/
755769
@available(macOS 11, *)
756770
@MainActor
757-
var toSwiftUI: KeyboardShortcut? {
771+
public var toSwiftUI: KeyboardShortcut? {
758772
if
759773
let key,
760774
let specialKey = keyToSpecialKeyMapping[key]

0 commit comments

Comments
 (0)