Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cocoa bindings for the Go language

Is it possible to write macOS/Cocoa applications in Google Go?

Is there a Go-Obj-C bridge? (it seems to me that Obj-C dynamism would be a great fit for Golang's interfaces)

Can I at least link the two together and make them talk to each other via plain-old C functions?

like image 926
Kornel Avatar asked Jun 12 '11 13:06

Kornel


2 Answers

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.

like image 126
Kissaki Avatar answered Sep 28 '22 00:09

Kissaki


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?

like image 35
Albin Stigo Avatar answered Sep 28 '22 00:09

Albin Stigo