Remove `Name` typealias in `KeyboardShortcuts.Name`

I realized you can just use `Self` instead 👌
This commit is contained in:
Sindre Sorhus 2020-06-25 03:08:15 +08:00
parent c7094b0b7a
commit a345f5f241
5 changed files with 8 additions and 10 deletions

View File

@ -2,8 +2,8 @@ import SwiftUI
import KeyboardShortcuts
extension KeyboardShortcuts.Name {
static let testShortcut1 = Name("testShortcut1")
static let testShortcut2 = Name("testShortcut2")
static let testShortcut1 = Self("testShortcut1")
static let testShortcut2 = Self("testShortcut2")
}
struct ContentView: View {

View File

@ -20,7 +20,7 @@ extension NSMenuItem {
import KeyboardShortcuts
extension KeyboardShortcuts.Name {
static let toggleUnicornMode = Name("toggleUnicornMode")
static let toggleUnicornMode = Self("toggleUnicornMode")
}
// `Recorder` logic for recording the keyboard shortcut
@ -65,6 +65,7 @@ extension NSMenuItem {
set()
}
// TODO: Use Combine when targeting macOS 10.15.
AssociatedKeys.observer[self] = NotificationCenter.default.addObserver(forName: .shortcutByNameDidChange, object: nil, queue: nil) { notification in
guard
let nameInNotification = notification.userInfo?["name"] as? KeyboardShortcuts.Name,

View File

@ -8,15 +8,12 @@ extension KeyboardShortcuts {
import KeyboardShortcuts
extension KeyboardShortcuts.Name {
static let toggleUnicornMode = Name("toggleUnicornMode")
static let toggleUnicornMode = Self("toggleUnicornMode")
}
```
*/
public struct Name: Hashable {
// These make it possible to use the types without the namespace.
// `extension KeyboardShortcuts.Name { static let x = Name("x") }`.
/// :nodoc:
public typealias Name = KeyboardShortcuts.Name
// This makes it possible to use `Shortcut` without the namespace.
/// :nodoc:
public typealias Shortcut = KeyboardShortcuts.Shortcut

View File

@ -55,6 +55,6 @@ extension KeyboardShortcuts {
@available(macOS 10.15, *)
struct SwiftUI_Previews: PreviewProvider {
static var previews: some View {
KeyboardShortcuts.Recorder(for: .Name("xcodePreview"))
KeyboardShortcuts.Recorder(for: .init("xcodePreview"))
}
}

View File

@ -43,7 +43,7 @@ First, register a name for the keyboard shortcut.
import KeyboardShortcuts
extension KeyboardShortcuts.Name {
static let toggleUnicornMode = Name("toggleUnicornMode")
static let toggleUnicornMode = Self("toggleUnicornMode")
}
```