【问题标题】:What does the single | mean in swift什么是单 |意思是迅速
【发布时间】:2016-08-06 04:44:40
【问题描述】:

我在 OS X 中构建菜单栏项时发现了一些示例代码。它使用了单个 |我不确定它的实际含义。

(我想做的是在菜单项的左键单击时调用一个函数,但让它在右键单击时显示菜单)

这是我的代码

//Get reference to main system status bar
let statusItem = NSStatusBar.systemStatusBar().statusItemWithLength(-1)
statusItem.image = icon
statusItem.menu = menuBar
if let statusButton = statusItem.button
{
    statusButton.target = self
    statusButton.action = #selector(statusItemClicked)

    statusButton.sendActionOn(Int(NSEventMask.RightMouseUpMask.rawValue | NSEventMask.LeftMouseUpMask.rawValue))

}

带有代码Left vs Right Click Status Bar Item Mac Swift 2的原始答案

【问题讨论】:

    标签: swift macos


    【解决方案1】:

    按位或,就像在大多数类 C 语言中一样。在这种情况下,它被用于组合标志。

    【讨论】:

    • 你明白它在这段代码中的作用吗?我打算对它做更多的研究。这段代码实际上不起作用,我不确定这是否是问题所在。
    • @Dallas 这是旧代码,应该重写,就像马特说的那样。看看他(非常好)书中的链接
    【解决方案2】:

    那一定是非常古老的代码。如今,在现代 Swift 中,NSEventMask is an Option Set。你可以说[NSEventMask.rightMouseUp, NSEventMask.leftMouseUp],你根本不需要 Int 演员表。 (或者如果您还没有更新到 Swift 3,案例名称将以大写字母开头。)

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-07-26
    • 1970-01-01
    • 1970-01-01
    • 2011-03-11
    • 2011-08-12
    • 2017-06-11
    • 2018-03-05
    • 2023-03-27
    相关资源
    最近更新 更多