Add a PRO Badge to macOS Menu Buttons in SwiftUI

Add a PRO Badge to macOS Menu Buttons in SwiftUI

Mark exclusive subscription features with the SwiftUI badge modifier

·

1 min read

You've just added a print feature to your macOS app after reading my other article Apply FocusedValue for Active macOS Scenes Only in SwiftUI.

You've decided to only offer it to users that have paid for a subscription called PRO (which isn't the case with Lyrcs, printing is FREE 😉).

Can you guess how easy it is?

DocumentGroup(newDocument: AppDocument()) { file in
    ContentView(document: file.$document)
}
.commands {
    CommandGroup(replacing: .printItem) {
        Button("Print...") {
            print?()
        }
        .keyboardShortcut("p", modifiers: [.command])
        .disabled(print == nil)
        .badge("PRO") // <--- All you need
    }
}

Easy! You may start to see some PRO badges in Lyrcs (but not for printing ❤️).