see here:
How to invoke a method on a NSViewRepresentable from a View?
a complete (minimal..) sample. Hop can help.