TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Writing Apps in Go and Swift

158 pointsby youngdynastyover 6 years ago

12 comments

iainmerrickover 6 years ago
<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 未加载
hellofunkover 6 years ago
&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 未加载
alexashkaover 6 years ago
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.
sshbover 6 years ago
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>
benatkinover 6 years ago
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 未加载
coldcodeover 6 years ago
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 未加载
saagarjhaover 6 years ago
Swift Strings can transparently map to UnsafePointer&lt;CChar&gt; when necessary; is there a reason why this doesn’t work in this case?
onderwegover 6 years ago
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>
tptacekover 6 years ago
How well does this work? Can you call a Go library function that spawns goroutines?
评论 #19030103 未加载
评论 #19033719 未加载
axaxsover 6 years ago
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.
bunnycornover 6 years ago
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 未加载
gcbw2over 6 years ago
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 未加载