EventMonitor.LeftMouseDownMask The expression type is ambiguous without additional context

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, .LeftMouseDownMaskit 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!

    //Event Monitering
    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)

        //Event Monitering
        eventMonitor = EventMonitor(mask: .LeftMouseDownMask | .RightMouseDownMask) { [unowned self] event in
            if self.popover.shown {
                self.closePopover(event)
            }
        }
        eventMonitor?.start()
        //////////////////////
    }

    func applicationWillTerminate(aNotification: NSNotification) {
        // Insert code here to tear down your application
    }


    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 .LeftMouseDownMaskchanged to something else in Swift 2 since the tutorial was made in Swift 1 (and I had a few more compatibility issues).

+4
source share
2 answers

The problem is fixed.

eventMonitor = EventMonitor(mask: .LeftMouseDownMask | .RightMouseDownMask) { [unowned self] event in eventMonitor = EventMonitor(mask: [.LeftMouseDownMask, .RightMouseDownMask]) { [unowned self] event in.

+9

Swift 3

.LeftMouseDownMask | .RightMouseDownMask

[NSEventMask.leftMouseDown, NSEventMask.rightMouseDown]
+4

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


All Articles