英文:
Cocoa bindings for the Go language
问题
可以在Google Go中编写macOS/Cocoa应用程序吗?
是否有Go-Obj-C桥接?(我觉得Obj-C的动态性将非常适合Golang的接口)
我至少可以将它们链接在一起,并通过普通的C函数使它们相互通信吗?
英文:
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?
答案1
得分: 11
CGo是一种使您能够调用C代码的功能。
目前似乎还没有可用的Cocoa绑定/库,但您可以参考GTK包。
英文:
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.
答案2
得分: 9
目前似乎没有将Cocoa与Go绑定的包。Cocoa是用Objective-C编写的,它是C的超集。Objective-C消息(至少过去是这样,不确定现代编译器)由编译器转换为C函数调用,类似于这样:
objc_msgSend(object, sel_getUid("foo:bar:err:"), var, var2, errVar);
因此,从Go中使用Cocoa是完全可能的。
如果你遇到了一个问题,发现你想在Go应用程序中使用Cocoa,我个人认为应该退一步,思考一下你要解决的问题。Cocoa大量使用命名参数,方法的签名可能会很长。这在Objective-C中效果很好,但我怀疑在Go中代码看起来是否会那么好。另一方面,Go解决了另一组问题。也许在Go中编写库(应用程序逻辑),在Objective-C/Cocoa中编写GUI代码会起到作用?
**简而言之:**在Go中编写模型,在Objective-C中编写GUI代码如何?
英文:
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?
答案3
得分: 2
你可以查看我的博客文章作为一个例子。恐怕我没有继续工作,但是这里有源代码可以帮助你设置一个裸的Cocoa/ObjC/Go项目。
如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()
}
英文:
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()
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论