Should we expect bindings to iOS cocoa anytime soon?

blov · · 670 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I&#39;ve seen several posts that outline the difficulties creating bindings for the mobile platforms (i.e. android or iOS), some of them claiming that&#39;s not even feasible(i.e. you would end-up writing some kind of non-go code) so I&#39;m wondering if frameworks binding is on any roadmap or it&#39;s just something that we shouldn&#39;t expect. Is it more a technical issue or a kind of grunt work issue? I imagine it should be possible to just &#34;generate&#34; these bindings. The release of Apple Swift as open source could actually help to write a binding generator, right?</p> <p>I&#39;m aware that Go has mobile support[0] but that seems to be the case only for games(i.e. no cocoa or android API support).</p> <p>[0] <a href="https://github.com/golang/mobile" rel="nofollow">https://github.com/golang/mobile</a></p> <hr/>**评论:**<br/><br/>koffiezet: <pre><p>I&#39;m not sure how Obj-C/Swift bindings work, but I would think they should be similar to C/C++? No idea though...</p> <p>I&#39;m not sure how you envision autogenerating stuff like that, it&#39;s more complex than you&#39;d think. There is stuff like <a href="http://www.swig.org/" rel="nofollow">swig</a> to generate C/C++ library wrappers, but even then you still need to do quite some manual preparations to get things working, and I don&#39;t think it can do Go-&gt;Objective-C...</p> <p>So it&#39;s probably down to some serious grunt work, having someone willing to do this stuff.</p> <p>Also mind that a blind 1:1 binding might not be what you want, or might even be possible due to differences in concepts in the languages.</p></pre>kjk: <pre><p>Don&#39;t expect good Cocoa bindings for Go. It&#39;s possible to do but the mismatch between how Cocoa/Objective-C sees the world and how Go sees the world means that bindings will be slow, tedious to write and awkward to use.</p> <p>Consider calling a simple Cocoa function like [NSButton setTitle:&#34;foo&#34;]. In Go, strings are binary blobs (possibly in utf8, but that&#39;s not enforced, so you really don&#39;t know the encoding). In Cocoa, strings are UTF 16. In a hypothetical Go binding, if you do button.setTitle(&#34;foo&#34;), &#34;foo&#34; has to be converted from byte string to UTF16, which is expensive (compared to function call) and you need to write a wrapper that does this conversion for every function that takes NSString as an arg. That&#39;s a lot of wrappers.</p> <p>This is only one example of Cocoa and Go mismatch. Cocoa is an object-oriented, dynamic runtime. Swift was explicitly designed for Objective-C/Cocoa interop. Go wasn&#39;t.</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

670 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传