KeyboardShortcuts icon indicating copy to clipboard operation
KeyboardShortcuts copied to clipboard

Get all shortcuts without maintenance / Automatic conformance to CaseIterable

Open soundflix opened this issue 3 years ago • 4 comments

Having to add all Shortcuts to .allCases manually can be tedious. I tried to solve with mirror API but it doesn't take static properties.

soundflix avatar May 01 '22 10:05 soundflix

Yeah, this is blocked by Swift having better reflection abilities.

sindresorhus avatar May 02 '22 01:05 sindresorhus

Why do you need to get all the shortcuts? Maybe there's a better way to solve your problem.

sindresorhus avatar May 02 '22 01:05 sindresorhus

I list all shortcuts in app preferences for the user to assign what he needs. Currently it’s 31.

soundflix avatar May 02 '22 10:05 soundflix

I assume you need a label for each shortcut and those have to be stored somewhere, so I think you need an array regardless. Hard for be to know without knowing exactly how your app is structured though.

sindresorhus avatar May 06 '22 07:05 sindresorhus

I thought i have to declare a static let for each KeyboardShortcut.Name. I found out i can simply dynamically initialize with a string and that store in an array or other structure. All fine.

soundflix avatar Nov 15 '22 21:11 soundflix