I've seen the usage like this in a subclass of an NSOutlineView
override func mouseDown(with event: NSEvent) {
super.mouseDown(with: event)
let location = self.convert(
event.locationInWindow,
to: nil)
let clickedRow = self.row(at: location)
}
The documentation of convert(_:to:)
says it
Converts a point from the view’s coordinate system to that of a given view.
So what I understood is it returns a point in the view (as the argument)'s coordinate system. In the above example, it's the window's.
The doc of row(at:)
of NSTableView
sasys it receives:
A point in the coordinate system of the table view.
I'm confused by the English here.
A related question is here: NSTableView: detecting a mouse click together with the row and column
Edit
Thanks to @Willeke's pointing out there's the sister of convert(_:to:)
, convert(_:from:)
. It's a coincidence that convert(_:to:)
also works in my case. But I should have used convert(_:from:)
. I overlooked the linked example.