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

iPr*_*ram 5 macos toolbar swift2

我正在学习使用Swift 2为Xcode创建一个状态栏应用程序.我已经接近完成了本教程,但是在线上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)
        }
    }


}
Run Code Online (Sandbox Code Playgroud)

我猜这个错误是因为.LeftMouseDownMask在Swift 1中已经改变了其他东西,因为教程是在Swift 1中制作的(我还有一些其他的兼容性问题).

iPr*_*ram 10

修复了这个问题.

我不得不改变线路eventMonitor = EventMonitor(mask: .LeftMouseDownMask | .RightMouseDownMask) { [unowned self] event ineventMonitor = EventMonitor(mask: [.LeftMouseDownMask, .RightMouseDownMask]) { [unowned self] event in.


que*_*ful 5

迅捷3

替换以下代码

.LeftMouseDownMask | .RightMouseDownMask
Run Code Online (Sandbox Code Playgroud)

有了这个

[NSEventMask.leftMouseDown, NSEventMask.rightMouseDown]
Run Code Online (Sandbox Code Playgroud)