NSCollectionView doesn't popup context menu?

I had the same issue with the "new" NSCollectionView. The contextual menu is set up in the xib, and it is actually correctly triggered by an actual right-click on the mouse, and also by double-finger tab on the trackpad (if the user has set that option in the System Preferences), but not by control-click. Thus it seems like a legitimate bug or limitation with NSCollectionView, maybe dependent on how it is set up.

In any case, here is a shorter solution, this one in Swift, that assumes you have otherwise set up the contextual menu using the menu outlet for the collection view (or you have it set up as outlined in Apple's documentation).

You will need to create a subclass of NSCollectionView and choose the subclass for the collection view in the xib. Here is the code for the subclass:

import Cocoa

class MyCollectionView: NSCollectionView {

    /// Fixes the behavior of collection view with control-click, that does not properly trigger the contextual menu.
    override func mouseDown(with event: NSEvent) {
        super.mouseDown(with: event)
        if event.type == .rightMouseDown || event.modifierFlags.contains(.control) {
            rightMouseDown(with: event)