cocoabits / MASShortcut

Modern framework for managing global keyboard shortcuts compatible with Mac App Store. More details:
http://blog.shpakovski.com/2012/07/global-keyboard-shortcuts-in-cocoa.html
BSD 2-Clause "Simplified" License
1.52k stars 220 forks source link

Can I add a Package.swift file and use it with SPM? #144

Closed rampatra closed 4 years ago

rampatra commented 4 years ago

I was thinking to add a Package.swift file like below:

// swift-tools-version:5.0
import PackageDescription

let package = Package(
    name: "MASShortcut",
    products: [
        .library(name: "Framework",
                 targets: ["Framework"])
    ],
    targets: [
        .target(name: "Framework",
                path: "Framework")
    ]
)

and then use it in my swift project. Can I do it?

rampatra commented 4 years ago

I actually went ahead and tried the above and I successfully added this library as a dependency but I tried to build it I got the below errors:

Screenshot 2020-04-17 at 22 21 33

Any ideas?

I am a complete greenhorn in swift so please pardon my naivety.

rampatra commented 4 years ago

The swift forum helped me here and I am now able to compile the code successfully but the library is behaving weirdly. Not sure what's going on.

The button shows xxx and doesn't work as it works in other apps like rectangle, etc.

Any help would be really appreciated.

shpakovski commented 4 years ago

Hi @rampatra Thanks for trying to wrap this code into a Swift Package. I cannot add an official SwiftPM support at the moment, but you’re moving in the right direction. Maybe xxx is displayed because localization tables are not available. Make sure to copy .strings into the main app’s Resources. Hope this helps, and sorry for the slow reply!

rampatra commented 4 years ago

No worries. I have currently gone with https://github.com/soffes/HotKey for now but I would be soon using this library after I've added a couple of urgent features in the app. I can update here once I am done.

iSapozhnik commented 4 years ago

@rampatra @shpakovski I think the problem here is that currently it's not possible to add any resources to SPM. But it will be possible pretty soon ;) https://forums.swift.org/t/se-0271-package-manager-resources/30730

rampatra commented 4 years ago

@iSapozhnik yes, so I have gone with the below code (in MASLocalization.m file) to allow only English translation for now:

return [localizationBundle localizedStringForKey:key
        value:key
        table:MASLocalizationTableName];

I have been able to successfully convert this library to a Swift Package.

All credit goes to https://forums.swift.org/t/can-i-use-swift-package-manager-in-obj-c-code/35463/19

rampatra commented 4 years ago

I am closing this as I've converted it to a Swift Package successfully here.

Thanks for all the help!