gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 16:39:01 24 4
gpt4 key购买 nike

我正在学习使用 Swift 2 为 Xcode 制作状态栏应用程序。我几乎完成了这个 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)
}
}


}

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

最佳答案

修复了问题。

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

关于macos - EventMonitor .LeftMouseDownMask 表达式类型不明确,没有更多上下文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33462970/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com