EventMonitor .LeftMouseDownMask 表达式类型不明确,没有更多上下文

EventMonitor .LeftMouseDownMask Type of expression is ambiguous without more context

我正在学习使用 Swift 为 Xcode 制作状态栏应用程序 2。我几乎完成了这个 tutorial,但是在线 eventMonitor = EventMonitor(mask: . | .RightMouseDownMask) { [unowned self] event in.LeftMouseDownMask 给我一个错误说 Type of expression is ambiguous without more context。我该如何解决这种类型的表达问题?

这是我的 AppDelegate.swift 文件:

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)
        }
    }


}

我猜这个错误是因为 .LeftMouseDownMask 在 Swift 2 中更改为其他内容,因为 tutorial 是在 Swift 1 中制作的(我有还有一些其他兼容性问题)。

已解决问题。

我不得不将行 eventMonitor = EventMonitor(mask: .LeftMouseDownMask | .RightMouseDownMask) { [unowned self] event in 更改为 eventMonitor = EventMonitor(mask: [.LeftMouseDownMask, .RightMouseDownMask]) { [unowned self] event in

Swift 3

替换以下代码

.LeftMouseDownMask | .RightMouseDownMask

有了这个

[NSEventMask.leftMouseDown, NSEventMask.rightMouseDown]