开发者

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开发者_JAVA百科?


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()
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜