I am studying to make an application for the status bar for Xcode using Swift 2. I almost finished this tutorial , however on the line eventMonitor = EventMonitor(mask: . | .RightMouseDownMask) { [unowned self] event in
, .LeftMouseDownMask
it gives me an error message Type of expression is ambiguous without more context
. How can I fix this type of expression?
Here is my AppDelegate.swift file:
import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
@IBOutlet weak var window: NSWindow!
var eventMonitor: EventMonitor?
let statusItem = NSStatusBar.systemStatusBar().statusItemWithLength(-2)
let popover = NSPopover()
func applicationDidFinishLaunching(notification: NSNotification) {
if let button = statusItem.button {
button.image = NSImage(named: "StatusBarButtonImage")
button.action = Selector("togglePopover:")
}
popover.contentViewController = QuotesViewController(nibName: "QuotesViewController", bundle: nil)
eventMonitor = EventMonitor(mask: .LeftMouseDownMask | .RightMouseDownMask) { [unowned self] event in
if self.popover.shown {
self.closePopover(event)
}
}
eventMonitor?.start()
}
func applicationWillTerminate(aNotification: NSNotification) {
}
func showPopover(sender: AnyObject?) {
if let button = statusItem.button {
popover.showRelativeToRect(button.bounds, ofView: button, preferredEdge: NSRectEdge.MinY)
}
}
func closePopover(sender: AnyObject?) {
popover.performClose(sender)
}
func togglePopover(sender: AnyObject?) {
if popover.shown {
closePopover(sender)
} else {
showPopover(sender)
}
}
}
I assume this error is due to being .LeftMouseDownMask
changed to something else in Swift 2 since the tutorial was made in Swift 1 (and I had a few more compatibility issues).
source
share