sindresorhus / KeyboardShortcuts

⌨️ Add user-customizable global keyboard shortcuts (hotkeys) to your macOS app in minutes
https://swiftpackageindex.com/sindresorhus/KeyboardShortcuts/documentation/keyboardshortcuts/keyboardshortcuts
MIT License
1.99k stars 185 forks source link

No such module 'Carbon.HIToolbox' #130

Closed bobmosh closed 1 year ago

bobmosh commented 1 year ago

Hey folks,

I just added the package to my personal Xcode project via SPM and the first thing that happens when I build is No such module 'Carbon.HIToolbox' in the CarbonKeyboardShortcuts.swift.

I tried the latest version tags as well as pulling from main, butt the issue doesn't seem to be resolvable. Anyone else have the same issue?

Cheers, Ferdi

bobmosh commented 1 year ago

For context I am using this in an App that will also have an iOS App, so it might be connected to that, could that be?

bobmosh commented 1 year ago

Solved it myself!

For anyone wondering, the library only builds for macOS targets. In order to use it in a cross platform environment, you will need to use conditional exclusion like #if os(macOS) on any imports / usage of code from that library (use safer methods if possible though, this is just what I used in my tests).

You will also need multiple targets (I separated my App targets into iOS/iPadOS and macOS) and remove the linked library from the Frameworks, Libraries, and Embedded Content section of the mobile targets.

WalterZou commented 1 year ago

@bobmosh I also encountered this problem. I added #if os(macOS) to all the places where this library is used, but it still gives an error: image

Is there any way to resolve this case without involving multiple targets?

WalterZou commented 1 year ago

By adding the conditional statement #if os(macOS) ... #endif to all the code of KeyboardShortcuts, I have resolved this issue by ensuring that the source code only compiles on macOS, without the need to build multiple targets.

sindresorhus commented 1 year ago

You will also need multiple targets (I separated my App targets into iOS/iPadOS and macOS) and remove the linked library from the Frameworks, Libraries, and Embedded Content section of the mobile targets.

You don't need to do that. You can make it only used for a specific platform:

Screenshot 2023-07-26 at 19 35 26
WalterZou commented 1 year ago

You will also need multiple targets (I separated my App targets into iOS/iPadOS and macOS) and remove the linked library from the Frameworks, Libraries, and Embedded Content section of the mobile targets.

You don't need to do that. You can make it only used for a specific platform:

Screenshot 2023-07-26 at 19 35 26

I have already set it to only used for macOS, but it still throws the error, so I used conditional statements to wrap all the files to fix the issue