A simple DSL for NSMenu and NSMenuItem.
Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.
You can install Carthage with Homebrew using the following command:
$ brew update
$ brew install carthage
To integrate MenuBuilder into your Xcode project using Carthage, specify it in your Cartfile
:
github "zetasq/MenuBuilder"
Run carthage update
to build the framework and drag the built MenuBuilder.framework
into your Xcode project.
// Create an NSMenu and open a context to create items
let rootMenu = NSMenu().withBuildContext { context in
// Create a submenu in the current context
context.addSubmenu(title: "Test") { context in
// Add "About Test" menuitem in the current submenu context
context.addItem(title: "About Test", action: #selector(NSApplication.orderFrontStandardAboutPanel(_:)))
// Add a separator menuitem
context.addSeparator()
// Add several other items
context.addItem(title: "Hide Test", action: #selector(NSApplication.hide(_:)), baseKey: "h", keyModifiers: [.command])
context.addItem(title: "Hide Others", action: #selector(NSApplication.hideOtherApplications(_:)), baseKey: "h", keyModifiers: [.option, .command])
context.addItem(title: "Show All", action: #selector(NSApplication.unhideAllApplications(_:)))
context.addItem(title: "Quit Test", action: #selector(NSApplication.terminate(_:)), baseKey: "q", keyModifiers: .command)
}
}
// Assign the rootMenu to the application's mainMenu
NSApplication.shared().mainMenu = rootMenu