TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Writing Apps in Go and Swift

158 点作者 youngdynasty超过 6 年前

12 条评论

iainmerrick超过 6 年前
<i>I still find it hard to write maintainable multi-threaded code for macOS or iOS [...] without having to worry about the minutiae of parallelism (threads, semaphores, locks, barriers, etc.).</i><p>I find this surprising, as GCD does insulate you from that low-level stuff. When you need to work with mutable data, just create a dispatch queue, and only ever access the data by dispatching a function to the queue. Both Swift and Objective-C have friendly syntax for anonymous functions that makes this lightweight and easy.
评论 #19029599 未加载
评论 #19031269 未加载
评论 #19029758 未加载
hellofunk超过 6 年前
&gt; Give Emporter a try and let me know how it compares to an Electron app.<p>I don&#x27;t see how this technique is comparable to Electron. The article does not describe anything related to a cross-platform user interface, which is what Electron addresses. You can write non-UI logic that is cross-platform in half a dozen mainstream languages and another dozen less popular ones. That&#x27;s not a big deal. It&#x27;s the UI component that is harder to achieve, and that is what Electron offers.
评论 #19030159 未加载
评论 #19029665 未加载
alexashka超过 6 年前
Just wanted to say that module maps are absolutely not necessary to have static libraries (.a file author compiles his go program to) in your project.<p>All you need is an objective-c bridging header where you do an #import &quot;name_of_header_.h&quot; for every header. After that, the headers are visible to all of your swift code. It&#x27;s no different than mixing objective-c and swift, except here you&#x27;re mixing your language of choice, compiled to callable C functions inside a static library.<p>To recap - drag .h and .a files the same way you have .swift files into your xcode project. Add a BridgingHeader.h file, go to it, fill it with #import &quot;name_of_header.h&quot; statements. Lastly, the project needs to know you&#x27;re using a bridging header, that&#x27;s done in the project target&#x27;s Build Settings tab, under &quot;Objective-C Bridging Header&quot; you need to have the value set to the filename you chose for your bridging header.<p>This is not unique to calling Go in Swift btw - any language that can be called from C, can be called from Objective-C, and therefore Swift. One thing to be aware of is memory management - unless you&#x27;re passing things by value (copying), making sense of when things can be safely deallocated across languages is non-trivial.
sshb超过 6 年前
Go has great crypto library, so I&#x27;ve wrapped it for use with Swift: <a href="https:&#x2F;&#x2F;github.com&#x2F;lastochkanetwork&#x2F;EasyPGP" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;lastochkanetwork&#x2F;EasyPGP</a>
benatkin超过 6 年前
Heads up: you made this error at least twice, once in the article and once in the repo. <a href="https:&#x2F;&#x2F;brians.wsu.edu&#x2F;2016&#x2F;05&#x2F;31&#x2F;complement-compliment&#x2F;" rel="nofollow">https:&#x2F;&#x2F;brians.wsu.edu&#x2F;2016&#x2F;05&#x2F;31&#x2F;complement-compliment&#x2F;</a> It&#x27;s complementary instead of complimentary. The word &quot;complimentary&quot; is rarely used, but could be used if you were to mention books related to complimenting people.
评论 #19030078 未加载
coldcode超过 6 年前
I don&#x27;t find GCD difficult to write for, maybe if you are used to Go it is different enough. Not sure what exactly you would use Go for in an iOS&#x2F;Macos app unless maybe you have a Go framework you want to include.
评论 #19029628 未加载
评论 #19030739 未加载
saagarjha超过 6 年前
Swift Strings can transparently map to UnsafePointer&lt;CChar&gt; when necessary; is there a reason why this doesn’t work in this case?
onderweg超过 6 年前
I found your article particularly interesting, because lately I&#x27;ve been experimenting with calling Swift from Go.<p>The approach is based on the same principle: cgo as bridge between Go and a C library. The C library is build by the Swift package manager. Blog post on Dev community with details:<p><a href="https:&#x2F;&#x2F;dev.to&#x2F;gerwert&#x2F;calling-swift-from-go-5dbk" rel="nofollow">https:&#x2F;&#x2F;dev.to&#x2F;gerwert&#x2F;calling-swift-from-go-5dbk</a>
tptacek超过 6 年前
How well does this work? Can you call a Go library function that spawns goroutines?
评论 #19030103 未加载
评论 #19033719 未加载
axaxs超过 6 年前
Thanks for sharing this! As someone who writes in Go every day but stopped following it a while back, I had no idea you could even call Go from C much less Swift.
bunnycorn超过 6 年前
Someone that doesn&#x27;t know how to write Swift, tries to find faults at all costs.<p>Go, horrible as it is, doesn&#x27;t lack cultists.
评论 #19031431 未加载
gcbw2超过 6 年前
I am go ahead and say it: Go is a replacement for Perl. It is nice for process and machine administration automation. Can you write your app in go? yes. Could you also write your app in perl cgi? sure. Did many people wrote perl cgi apps? yes. did they regret it. yes. Will people writing apps in go will regret it? who knows. Probably yes.<p>This comment is not about the language per-se. it is about the current goals of the people with money and weight behind the language right now. I guess the regret will come or not if those goals keep or change.
评论 #19031444 未加载
评论 #19030833 未加载
评论 #19031139 未加载
评论 #19030453 未加载
评论 #19030507 未加载