Cocoa bindings for the Go language

CGo is what enables you to call C code.

See the CGo doc and the informative, official blog post on it.

There does not seem to be cocoa bindings/libraries yet, but you may want to check out the GTK package for reference.


Right now there doesn't seem to be a package for binding Cocoa to Go. Cocoa is written in Objective-C which is a superset of C. Objective-C messages are (or at least used to be, not sure about the modern compilers) translated to C function calls by the compiler, to something like this:

objc_msgSend(object, sel_getUid("foo:bar:err:"), var, var2, errVar);

So it's definitely possible to use Cocoa from Go.

If you run in to a problem where you find you would like to use Cocoa in a Go app, IMHO take a step back and think about the problem you're trying to solve. Cocoa makes heavy use of named parameters and methods can have quite long signatures. This works well in Objective-C but I doubt the code would look as good in Go. On the other hand, Go solves another set of problems. Maybe writing a library (application logic) in Go and GUI code in Objective-C/Cocoa would do the trick?

TL;DR: How about writing model in Go and GUI code in Objective-C?


You can have a look at my blog post as an example. I'm afraid I didn't keep working on it, but here's the source code that can help you setting up a bare Cocoa/ObjC/Go project.

You're gonna be able to do something like this, as mentioned in the README.

package main

import (
  "github.com/alediaferia/gogoa"
)

func main() {
    app := gogoa.SharedApplication()
    window := gogoa.NewWindow(0, 0, 200, 200)
    window.SetTitle("Gogoga!")
    window.MakeKeyAndOrderFront()

    app.Run()
}