我是 OSX 编程的新手,最近开始了一个 OS X 10.10 的演示项目。找到这个 -> http://cocoatutorial.grapewave.com/tag/menulet/在 OSX 状态栏中添加 menulet 的好教程。问题是我的项目使用的是 swift 语言,方法和项目结构/文件有些不同。我想知道是否有人在优胜美地上成功尝试过这个?谢谢。
编辑:具体问题是如何替换 awakefromnib 方法以使用当前的 AppDelegate.swift 语法?
我是 OSX 编程的新手,最近开始了一个 OS X 10.10 的演示项目。找到这个 -> http://cocoatutorial.grapewave.com/tag/menulet/在 OSX 状态栏中添加 menulet 的好教程。问题是我的项目使用的是 swift 语言,方法和项目结构/文件有些不同。我想知道是否有人在优胜美地上成功尝试过这个?谢谢。
编辑:具体问题是如何替换 awakefromnib 方法以使用当前的 AppDelegate.swift 语法?
整个事情就是这样...
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")
}
}
我刚刚从您的链接中复制了它,并翻译成 Swift。它仍然显示一个窗口等,应该很容易删除......更新显示了如何......
(当然我在优胜美地上运行它)