OS X 10.10 Yosemite - adding a menu set

I am new to OSX programming and recently started a demo project for OS X 10.10. Found this -> http://cocoatutorial.grapewave.com/tag/menulet/ a good tutorial to add a menu to the OSX status bar. The problem is that my project uses a fast language, and the methods and structure of the project / files are slightly different. I would like to know if anyone successfully tried this in Yosemite? Thanks.

Edit: The specific question is how to replace the awakefromnib method with the real AppDelegate.swift syntax?

+2
source share
1 answer

All this...

class AppDelegate: NSObject, NSApplicationDelegate { @IBOutlet var window: NSWindow // Remove this and delete window in IB to remove window // ... also, remove MainMenu from IB. @IBOutlet var statusMenu: NSMenu var statusItem: NSStatusItem? = nil func applicationDidFinishLaunching(aNotification: NSNotification?) { // Insert code here to initialize your application } func applicationWillTerminate(aNotification: NSNotification?) { // Insert code here to tear down your application } override func awakeFromNib() { self.statusItem = NSStatusBar.systemStatusBar().statusItemWithLength(CGFloat(NSVariableStatusItemLength)) self.statusItem!.menu = self.statusMenu self.statusItem!.title = "Status" self.statusItem!.highlightMode = true } @IBAction func doSomethingWithMenuSelection(sender : AnyObject) { println("Action pressed") } } 

I just copied it from your link and translated it to Swift. It still shows a window, etc. Which should be trivial to remove ... UPDATE showed how ...

(and of course I run it on Yosemite)

+3
source

Source: https://habr.com/ru/post/970611/


All Articles