Dallas Dallas - 11 months ago 42
Swift Question

What does the single | mean in swift

I found some example code when building a menu bar item in OS X. It makes use of the single | and I'm unsure what it actually means.

(What I'm trying to do is have a function called on left click of the menu item, but have it show the menu on right click)

Here's my code

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


Original Answer with code Left vs Right Click Status Bar Item Mac Swift 2


That must be really old code. Nowadays, in modern Swift, NSEventMask is an Option Set. You can just say [NSEventMask.rightMouseUp, NSEventMask.leftMouseUp], and you don't need the Int cast at all. (Or if you haven't updated to Swift 3 yet, the case names would start with capital letters.)