- Notifications
You must be signed in to change notification settings - Fork0
Go Goodies for Swift. Including goroutines, channels, defer, and panic.
License
Alphasite/GoSwift
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
# GoSwift - Go Goodies for Swift
Bring some of the more powerful features of Go to your iOS / Swift project such as channels, goroutines, and defers.
This is an experimental project. For production use of channels and sync APIs, check out theSafe project.
Built for Swift 2.0 - For Swift 1.2 support use v0.1.4 or earlier.
##Features
- Goroutines
- Defer
- Panic, Recover
- Channels
- Buffered Channels
- Select, Case, Default
- Closing
- Sync Package
- Mutex, Cond, Once, WaitGroup
##Example
Note that the following example and all of the examples in theexamples
directory originated fromhttp://gobyexample.com and Mark McGranaghan
Go
package mainimport"fmt"funcmain() {jobs:=make(chanint,5)done:=make(chanbool)gofunc() {for {j,more:=<-jobsifmore {fmt.Println("received job",j)}else {fmt.Println("received all jobs")done<-truereturn}}}()forj:=1;j<=3;j++ {jobs<-jfmt.Println("sent job",j)}close(jobs)fmt.Println("sent all jobs")<-done}
Swift
func main(){varjobs=Chan<Int>(5)vardone=Chan<Bool>()go{for ;;{var(j, more)=<?jobsif more{println("received job\(j!)")}else{println("received all jobs")done<-truereturn}}}forvar j=1; j<=3; j++{jobs<- jprintln("sent job\(j)")}close(jobs)println("sent all jobs")<-done}
###Run an Example
Each example has a.swift
and.go
file that contain the same logic.
./run.sh examples/goroutines.swift./run.sh examples/goroutines.go
##Installation (iOS and OS X)
Add the following to your Cartfile:
github "tidwall/GoSwift"
Then runcarthage update
.
Follow the current instructions inCarthage's READMEfor up to date installation instructions.
Theimport GoSwift
directive is required in order to access GoSwift features.
Add the following to yourPodfile:
use_frameworks!pod'GoSwift'
Then runpod install
with CocoaPods 0.36 or newer.
Theimport GoSwift
directive is required in order to access GoSwift features.
###Manually
Copy theGoSwift\go.swift
file into your project.
There is no need forimport GoSwift
when manually installing.
Josh Baker@tidwall
The GoSwift source code available under the MIT License.
The Go source code in theexamples
directory is copyright Mark McGranaghan and licensed under aCreative Commons Attribution 3.0 Unported License.
The Swift version of the example code is by Josh Baker
About
Go Goodies for Swift. Including goroutines, channels, defer, and panic.
Resources
License
Stars
Watchers
Forks
Packages0
Languages
- Swift67.4%
- Go26.2%
- Shell2.7%
- Ruby2.2%
- C++1.5%