Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Go Goodies for Swift. Including goroutines, channels, defer, and panic.

License

NotificationsYou must be signed in to change notification settings

Alphasite/GoSwift

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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.

Contact

Josh Baker@tidwall

License

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

Packages

No packages published

Languages

  • Swift67.4%
  • Go26.2%
  • Shell2.7%
  • Ruby2.2%
  • C++1.5%

[8]ページ先頭

©2009-2025 Movatter.jp