DEV Community

Jeff Lindsay
Jeff Lindsay

Posted on

Go to Objective-C bridge works!

Late last night I made a breakthrough and finally got the Go Objective-C bridge working. This just shows a "Hello world" window so it might seem like that's all there is. But the hard work has been in making the bridge code work at all for any kind of method call.

img

What this means is any Apple API can be used from Go. And since Apple has schemas for every one of their APIs, I can generate wrappers for them so it all feels like native Go.

Top comments (2)

Collapse
 
jjude profile image
Joseph Jude

This is fantastic. Any reason you are building a bridge to objective-c and not to swift?

Collapse
 
progrium profile image
Jeff Lindsay

I don't know if this is an easy question to answer. I guess the main reason is that afaik Swift doesn't have anything like libobjc that gives you access to the runtime. And then also because sooo much of Apple software is based on the Objective-C runtime, Swift either reimplements or is based on that same runtime behind the scenes. Ultimately most of the frameworks you want to use are actually written in Objective-C even if they're available in Swift, so there isn't much of a reason to bridge to Swift even if it were possible.

Ultimately we want access to the APIs and frameworks, not the language, but we need the runtime to use those APIs. Though it's interesting that because Objective-C is so dynamic and runtime oriented, it would give a language like Go the ability to create classes and instances of those classes at runtime. I don't think that is very useful in practice, but an interesting side-effect of bridging the runtimes.