├── .gitattributes ├── .gitignore ├── README.md ├── build └── .gitkeep ├── code ├── arrays.go ├── arrays.swift ├── checking-type.go ├── checking-type.swift ├── declaration.go ├── declaration.swift ├── downcasting.go ├── downcasting.swift ├── empty-collections.go ├── empty-collections.swift ├── explicit-types.go ├── explicit-types.swift ├── extensions.go ├── extensions.swift ├── function-type.go ├── function-type.swift ├── functions.go ├── functions.swift ├── hello-world.go ├── hello-world.swift ├── inclusive-range-operator.go ├── inclusive-range-operator.swift ├── map.go ├── map.swift ├── maps.go ├── maps.swift ├── named-arguments.go ├── named-arguments.swift ├── protocol.go ├── protocol.swift ├── range-operator.go ├── range-operator.swift ├── sort.go ├── sort.swift ├── string-interpolation.go ├── string-interpolation.swift ├── subclass.go ├── subclass.swift ├── tuple-return.go ├── tuple-return.swift ├── type-coercion.go ├── type-coercion.swift ├── usage.go ├── usage.swift ├── variable-number-of-arguments.go ├── variable-number-of-arguments.swift ├── variables-and-constants.go └── variables-and-constants.swift ├── css └── style.css ├── index.cirru ├── package.json ├── tasks ├── render.coffee └── rsync.sh └── yarn.lock /.gitattributes: -------------------------------------------------------------------------------- 1 | 2 | yarn.lock -diff 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | node_modules/ 3 | build/index.html 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | [Swift is like Go](http://repo.tiye.me/jiyinyiyong/swift-is-like-go/) 3 | ------ 4 | 5 | Also suggesting: 6 | 7 | > C, Go, Swift: a side-by-side reference sheet http://hyperpolyglot.org/c 8 | 9 | ### Develop 10 | 11 | ```bash 12 | yarn 13 | yarn build 14 | ``` 15 | 16 | HTML is generated from `index.cirru`, based [cirru-html](https://github.com/Cirru/cirru-html). Paste Cirru code into [Cirru Text Parser](http://repo.cirru.org/cirru-parser/) to understand it, [find out more](http://text.cirru.org/). 17 | 18 | ### Contributors 19 | 20 | * [@chai2010](https://github.com/chai2010/swift-is-like-go) 21 | * [@octo](https://github.com/octo/swift-is-like-go) 22 | * [@zhangxiaolian1991](https://github.com/zhangxiaolian1991/swift-is-like-go) 23 | 24 | ### Inspired 25 | 26 | * like Scala: https://leverich.github.io/swiftislikescala/ 27 | * Like C# ~~http://swiftcomparsion.qiniudn.com/~~ (a similiar page https://myquay.github.io/swift-is-like-c-sharp/) 28 | 29 | ### License 30 | 31 | MIT 32 | -------------------------------------------------------------------------------- /build/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tiye/swift-is-like-go/a524a3e7c16f340f2b03a0d715786b62fb643627/build/.gitkeep -------------------------------------------------------------------------------- /code/arrays.go: -------------------------------------------------------------------------------- 1 | var shoppingList = []string{"catfish", "water", 2 | "tulips", "blue paint"} 3 | shoppingList[1] = "bottle of water" -------------------------------------------------------------------------------- /code/arrays.swift: -------------------------------------------------------------------------------- 1 | var shoppingList = ["catfish", "water", 2 | "tulips", "blue paint"] 3 | shoppingList[1] = "bottle of water" -------------------------------------------------------------------------------- /code/checking-type.go: -------------------------------------------------------------------------------- 1 | var movieCount = 0 2 | var songCount = 0 3 | 4 | for _, item := range(library) { 5 | if _, ok := item.(Movie); ok { 6 | movieCount++ 7 | } else if _, ok := item.(Song); ok { 8 | songCount++ 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /code/checking-type.swift: -------------------------------------------------------------------------------- 1 | var movieCount = 0 2 | var songCount = 0 3 | 4 | for item in library { 5 | if item is Movie { 6 | ++movieCount 7 | } else if item is Song { 8 | ++songCount 9 | } 10 | } -------------------------------------------------------------------------------- /code/declaration.go: -------------------------------------------------------------------------------- 1 | type Shape struct { 2 | numberOfSides int 3 | } 4 | func (p *Shape) simpleDescription() string { 5 | return fmt.Sprintf("A shape with %d sides.", p.numberOfSides) 6 | } -------------------------------------------------------------------------------- /code/declaration.swift: -------------------------------------------------------------------------------- 1 | class Shape { 2 | var numberOfSides = 0 3 | func simpleDescription() -> String { 4 | return "A shape with \(numberOfSides) sides." 5 | } 6 | } -------------------------------------------------------------------------------- /code/downcasting.go: -------------------------------------------------------------------------------- 1 | for object := range someObjects { 2 | movie := object.(Movie) 3 | fmt.Printf("Movie: '%s', dir. %s", movie.name, movie.director) 4 | } -------------------------------------------------------------------------------- /code/downcasting.swift: -------------------------------------------------------------------------------- 1 | for object in someObjects { 2 | let movie = object as Movie 3 | print("Movie: '\(movie.name)', dir. \(movie.director)") 4 | } -------------------------------------------------------------------------------- /code/empty-collections.go: -------------------------------------------------------------------------------- 1 | var ( 2 | emptyArray []string 3 | emptyDictionary = make(map[interface{}]interface{}) 4 | emptyArrayNoType []interface{} 5 | ) -------------------------------------------------------------------------------- /code/empty-collections.swift: -------------------------------------------------------------------------------- 1 | let emptyArray = [String]() 2 | let emptyDictionary = [String: Float]() 3 | let emptyArrayNoType = [] -------------------------------------------------------------------------------- /code/explicit-types.go: -------------------------------------------------------------------------------- 1 | const explicitDouble float64 = 70 -------------------------------------------------------------------------------- /code/explicit-types.swift: -------------------------------------------------------------------------------- 1 | let explicitDouble: Double = 70 -------------------------------------------------------------------------------- /code/extensions.go: -------------------------------------------------------------------------------- 1 | type double float64 2 | 3 | func (d double) km() double { return d * 1000 } 4 | func (d double) m() double { return d } 5 | func (d double) cm() double { return d / 100 } 6 | func (d double) mm() double { return d / 1000 } 7 | func (d double) ft() double { return d / 3.28084 } 8 | 9 | func main() { 10 | var oneInch = double(25.4).mm() 11 | fmt.Printf("One inch is %v meters\n", oneInch) 12 | // prints "One inch is 0.0254 meters" 13 | 14 | var threeFeet = double(3).ft() 15 | fmt.Printf("Three feet is %v meters\n", threeFeet) 16 | // prints "Three feet is 0.914399970739201 meters" 17 | } -------------------------------------------------------------------------------- /code/extensions.swift: -------------------------------------------------------------------------------- 1 | extension Double { 2 | var km: Double { return self * 1_000.0 } 3 | var m: Double { return self } 4 | var cm: Double { return self / 100.0 } 5 | var mm: Double { return self / 1_000.0 } 6 | var ft: Double { return self / 3.28084 } 7 | } 8 | let oneInch = 25.4.mm 9 | print("One inch is \(oneInch) meters") 10 | // prints "One inch is 0.0254 meters" 11 | let threeFeet = 3.ft 12 | print("Three feet is \(threeFeet) meters") 13 | // prints "Three feet is 0.914399970739201 meters" -------------------------------------------------------------------------------- /code/function-type.go: -------------------------------------------------------------------------------- 1 | func makeIncrementer() func(int) int { 2 | return func (number int) int { 3 | return 1 + number 4 | } 5 | } 6 | 7 | func main() { 8 | increment := makeIncrementer() 9 | increment(7) 10 | } -------------------------------------------------------------------------------- /code/function-type.swift: -------------------------------------------------------------------------------- 1 | func makeIncrementer() -> (Int -> Int) { 2 | func addOne(number: Int) -> Int { 3 | return 1 + number 4 | } 5 | return addOne 6 | } 7 | var increment = makeIncrementer() 8 | increment(7) -------------------------------------------------------------------------------- /code/functions.go: -------------------------------------------------------------------------------- 1 | func greet(name, day string) string { 2 | return fmt.Sprintf("Hello %v, today is %v.", name, day) 3 | } 4 | 5 | func main() { 6 | greet("Bob", "Tuesday") 7 | } -------------------------------------------------------------------------------- /code/functions.swift: -------------------------------------------------------------------------------- 1 | func greet(name: String, day: String) -> String { 2 | return "Hello \(name), today is \(day)." 3 | } 4 | greet("Bob", "Tuesday") -------------------------------------------------------------------------------- /code/hello-world.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | fmt.Println("Hello, world!") 7 | } -------------------------------------------------------------------------------- /code/hello-world.swift: -------------------------------------------------------------------------------- 1 | print("Hello, world!") -------------------------------------------------------------------------------- /code/inclusive-range-operator.go: -------------------------------------------------------------------------------- 1 | for i := 1; i <= 5; i++ { 2 | fmt.Printf("%d times 5 is %d", i, i*5) 3 | } 4 | // 1 times 5 is 5 5 | // 2 times 5 is 10 6 | // 3 times 5 is 15 7 | // 4 times 5 is 20 8 | // 5 times 5 is 25 -------------------------------------------------------------------------------- /code/inclusive-range-operator.swift: -------------------------------------------------------------------------------- 1 | for index in 1...5 { 2 | print("\(index) times 5 is \(index * 5)") 3 | } 4 | // 1 times 5 is 5 5 | // 2 times 5 is 10 6 | // 3 times 5 is 15 7 | // 4 times 5 is 20 8 | // 5 times 5 is 25 -------------------------------------------------------------------------------- /code/map.go: -------------------------------------------------------------------------------- 1 | mapFunc := func(slice interface{}, fn func(a interface{}) interface{}) interface{} { 2 | val := reflect.ValueOf(slice) 3 | out := reflect.MakeSlice(reflect.TypeOf(slice), val.Len(), val.Cap()) 4 | for i := 0; i < val.Len(); i++ { 5 | out.Index(i).Set( 6 | reflect.ValueOf(fn(val.Index(i).Interface())), 7 | ) 8 | } 9 | return out.Interface() 10 | } 11 | a := mapFunc([]int{1, 2, 3, 4}, func(val interface{}) interface{} { 12 | return val.(int) * 3 13 | }) -------------------------------------------------------------------------------- /code/map.swift: -------------------------------------------------------------------------------- 1 | var numbers = [20, 19, 7, 12] 2 | numbers.map({ number in 3 * number }) -------------------------------------------------------------------------------- /code/maps.go: -------------------------------------------------------------------------------- 1 | var occupations = map[string]string{ 2 | "Malcolm": "Captain", 3 | "Kaylee": "Mechanic", 4 | } 5 | occupations["Jayne"] = "Public Relations" -------------------------------------------------------------------------------- /code/maps.swift: -------------------------------------------------------------------------------- 1 | var occupations = [ 2 | "Malcolm": "Captain", 3 | "Kaylee": "Mechanic", 4 | ] 5 | occupations["Jayne"] = "Public Relations" -------------------------------------------------------------------------------- /code/named-arguments.go: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tiye/swift-is-like-go/a524a3e7c16f340f2b03a0d715786b62fb643627/code/named-arguments.go -------------------------------------------------------------------------------- /code/named-arguments.swift: -------------------------------------------------------------------------------- 1 | func area(width: Int, height: Int) -> Int { 2 | return width * height 3 | } 4 | 5 | area(width: 10, height: 10) 6 | -------------------------------------------------------------------------------- /code/protocol.go: -------------------------------------------------------------------------------- 1 | type Nameabler interface { 2 | func Name() string 3 | } 4 | 5 | func F(x Nameabler) { 6 | fmt.Println("Name is " + x.Name()) 7 | } -------------------------------------------------------------------------------- /code/protocol.swift: -------------------------------------------------------------------------------- 1 | protocol Nameable { 2 | func name() -> String 3 | } 4 | 5 | func f(x: T) { 6 | print("Name is " + x.name()) 7 | } -------------------------------------------------------------------------------- /code/range-operator.go: -------------------------------------------------------------------------------- 1 | names := [4]string{"Anna", "Alex", "Brian", "Jack"} 2 | for i, value := range(names) { 3 | fmt.Printf("Person %v is called %v\n", (i + 1), value) 4 | } 5 | // Person 1 is called Anna 6 | // Person 2 is called Alex 7 | // Person 3 is called Brian 8 | // Person 4 is called Jack -------------------------------------------------------------------------------- /code/range-operator.swift: -------------------------------------------------------------------------------- 1 | let names = ["Anna", "Alex", "Brian", "Jack"] 2 | let count = names.count 3 | for i in 0..count { 4 | print("Person \(i + 1) is called \(names[i])") 5 | } 6 | // Person 1 is called Anna 7 | // Person 2 is called Alex 8 | // Person 3 is called Brian 9 | // Person 4 is called Jack -------------------------------------------------------------------------------- /code/sort.go: -------------------------------------------------------------------------------- 1 | sort.Sort(sort.Reverse(sort.IntSlice([]int{1, 5, 3, 12, 2}))) -------------------------------------------------------------------------------- /code/sort.swift: -------------------------------------------------------------------------------- 1 | sort([1, 5, 3, 12, 2]) { $0 > $1 } -------------------------------------------------------------------------------- /code/string-interpolation.go: -------------------------------------------------------------------------------- 1 | const apples = 3 2 | const oranges = 5 3 | fruitSummary := fmt.Sprintf("I have %d pieces of fruit.", apples + oranges) 4 | -------------------------------------------------------------------------------- /code/string-interpolation.swift: -------------------------------------------------------------------------------- 1 | let apples = 3 2 | let oranges = 5 3 | let fruitSummary = "I have \(apples + oranges) " + 4 | "pieces of fruit." -------------------------------------------------------------------------------- /code/subclass.go: -------------------------------------------------------------------------------- 1 | type NamedShape struct { 2 | numberOfSides int 3 | name string 4 | } 5 | func NewNamedShape(name string) *NamedShape { 6 | return &NamedShape{ 7 | name: name, 8 | } 9 | } 10 | func (p *NamedShape) SimpleDescription() string { 11 | return fmt.Sprintf("A shape with %d sides.", p.numberOfSides) 12 | } 13 | 14 | type Square struct { 15 | *NamedShape 16 | sideLength float64 17 | } 18 | func NewSquare(sideLength float64, name string) *Square { 19 | return &Square{ 20 | NamedShape: NewNamedShape(name), 21 | sideLength: sideLength, 22 | } 23 | } 24 | func (p *Square) Area() float64 { 25 | return p.sideLength * p.sideLength 26 | } 27 | func (p *Square) SimpleDescription() string { 28 | return fmt.Sprintf("A square with sides of length %d.", p.sideLength) 29 | } 30 | 31 | func main() { 32 | a := NewSquare(5.2, "square") 33 | a.Area() 34 | a.SimpleDescription() 35 | } 36 | -------------------------------------------------------------------------------- /code/subclass.swift: -------------------------------------------------------------------------------- 1 | class NamedShape { 2 | var numberOfSides: Int = 0 3 | var name: String 4 | 5 | init(name: String) { 6 | self.name = name 7 | } 8 | 9 | func simpleDescription() -> String { 10 | return "A shape with \(numberOfSides) sides." 11 | } 12 | } 13 | 14 | class Square: NamedShape { 15 | var sideLength: Double 16 | 17 | init(sideLength: Double, name: String) { 18 | self.sideLength = sideLength 19 | super.init(name: name) 20 | numberOfSides = 4 21 | } 22 | 23 | func area() -> Double { 24 | return sideLength * sideLength 25 | } 26 | 27 | override func simpleDescription() -> String { 28 | return "A square with sides of length 29 | \(sideLength)." 30 | } 31 | } 32 | 33 | let test = Square(sideLength: 5.2, name: "square") 34 | test.area() 35 | test.simpleDescription() -------------------------------------------------------------------------------- /code/tuple-return.go: -------------------------------------------------------------------------------- 1 | func getGasPrices() (float64, float64, float64) { 2 | return 3.59, 3.69, 3.79 3 | } -------------------------------------------------------------------------------- /code/tuple-return.swift: -------------------------------------------------------------------------------- 1 | func getGasPrices() -> (Double, Double, Double) { 2 | return (3.59, 3.69, 3.79) 3 | } -------------------------------------------------------------------------------- /code/type-coercion.go: -------------------------------------------------------------------------------- 1 | const label = "The width is " 2 | const width = 94 3 | var widthLabel = label + strconv.Itoa(width) -------------------------------------------------------------------------------- /code/type-coercion.swift: -------------------------------------------------------------------------------- 1 | let label = "The width is " 2 | let width = 94 3 | let widthLabel = label + String(width) -------------------------------------------------------------------------------- /code/usage.go: -------------------------------------------------------------------------------- 1 | var shape = new(Shape) 2 | shape.numberOfSides = 7 3 | var shapeDescription = shape.simpleDescription() 4 | -------------------------------------------------------------------------------- /code/usage.swift: -------------------------------------------------------------------------------- 1 | var shape = Shape() 2 | shape.numberOfSides = 7 3 | var shapeDescription = shape.simpleDescription() -------------------------------------------------------------------------------- /code/variable-number-of-arguments.go: -------------------------------------------------------------------------------- 1 | func sumOf(numbers ...int) int { 2 | var sum = 0 3 | for _, number := range(numbers) { 4 | sum += number 5 | } 6 | return sum 7 | } 8 | 9 | func main() { 10 | sumOf(42, 597, 12) 11 | sumOf([]int{42, 597, 12}...) 12 | } 13 | -------------------------------------------------------------------------------- /code/variable-number-of-arguments.swift: -------------------------------------------------------------------------------- 1 | func sumOf(numbers: Int...) -> Int { 2 | var sum = 0 3 | for number in numbers { 4 | sum += number 5 | } 6 | return sum 7 | } 8 | sumOf(42, 597, 12) -------------------------------------------------------------------------------- /code/variables-and-constants.go: -------------------------------------------------------------------------------- 1 | var myVariable = 42 2 | myVariable = 50 3 | const myConstant = 42 -------------------------------------------------------------------------------- /code/variables-and-constants.swift: -------------------------------------------------------------------------------- 1 | var myVariable = 42 2 | myVariable = 50 3 | let myConstant = 42 -------------------------------------------------------------------------------- /css/style.css: -------------------------------------------------------------------------------- 1 | 2 | body { 3 | font-family: "Helvetica Neue", sans-serif; 4 | margin: 0; 5 | } 6 | 7 | body * { 8 | box-sizing: border-box; 9 | } 10 | 11 | .section { 12 | background-color: #eee; 13 | padding: 80px; 14 | } 15 | 16 | .section:nth-child(2n) { 17 | background-color: white; 18 | } 19 | 20 | .title { 21 | font-size: 48px; 22 | color: #888; 23 | font-weight: 100; 24 | letter-spacing: 6px; 25 | text-align: center; 26 | } 27 | 28 | .case {} 29 | 30 | .name { 31 | font-size: 32px; 32 | color: #444; 33 | font-weight: 200; 34 | text-align: center; 35 | margin: 60px; 36 | } 37 | 38 | .pair { 39 | display: flex; 40 | display: -webkit-flex; 41 | display: -ms-flexbox; 42 | justify-content: center; 43 | -webkit-justify-content: center; 44 | -ms-box-pack: center; 45 | -ms-box-align: center; 46 | } 47 | 48 | .card { 49 | flex: 1; 50 | -webkit-flex: 1; 51 | -ms-flex: 1; 52 | max-width: 590px; 53 | margin: 0 10px; 54 | } 55 | 56 | .lang { 57 | font-size: 22px; 58 | color: #666; 59 | font-weight: 100; 60 | letter-spacing: 2px; 61 | } 62 | 63 | 64 | .code { 65 | background-color: white; 66 | color: #444; 67 | font-family: Menlo, monospace; 68 | padding: 0.5em; 69 | overflow-x: auto; 70 | } 71 | .section:nth-child(2n) .code { 72 | background-color: #eee; 73 | } 74 | 75 | #fork-me { 76 | position: absolute; 77 | right: 0; 78 | } 79 | 80 | #note { 81 | font-size: 24px; 82 | color: #A7A7A7; 83 | text-align: center; 84 | padding: 20px; 85 | background-color: rgb(221, 221, 221); 86 | font-weight: 100; 87 | line-height: 2em; 88 | } 89 | 90 | .hljs { 91 | background-color: transparent; 92 | } -------------------------------------------------------------------------------- /index.cirru: -------------------------------------------------------------------------------- 1 | 2 | doctype 3 | 4 | html 5 | head 6 | title "Swift is like Go" 7 | meta (:charset utf-8) 8 | link (:rel icon) 9 | :href http://logo.cirru.org/cirru-32x32.png 10 | :type image/png 11 | link (:rel stylesheet) 12 | :href https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.11.0/styles/github.min.css 13 | style (@insert css/style.css) 14 | script (:src https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.11.0/highlight.min.js) 15 | script (:src https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.11.0/languages/go.min.js) 16 | script (:src https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.11.0/languages/swift.min.js) 17 | script (:defer true) "hljs.initHighlightingOnLoad();" 18 | body 19 | a (:target _blank) 20 | :href https://github.com/jiyinyiyong/swift-is-like-go 21 | img#fork-me (:src http://jiyinyiyong.u.qiniudn.com/fork-me.png) 22 | #note 23 | = "Fork the repo if you want to help improve it. :)" 24 | br 25 | = "You may also check " 26 | a (:href http://hyperpolyglot.org/c) (:target _blank) 27 | = "Hyperpolyglot C, Go, Swift: a side-by-side reference sheet" 28 | .section 29 | .title BASICS 30 | .case (.name "Hello World") $ .pair 31 | .card (.lang Swift) $ pre.code $ code.swift (@insert code/hello-world.swift) 32 | .card (.lang Go ) $ pre.code $ code.go (@insert code/hello-world.go) 33 | .case (.name "Variables And Constants") $ .pair 34 | .card (.lang Swift) $ pre.code $ code.swift (@insert code/variables-and-constants.swift) 35 | .card (.lang Go ) $ pre.code $ code.go (@insert code/variables-and-constants.go) 36 | .case (.name "Explicit Types") $ .pair 37 | .card (.lang Swift) $ pre.code $ code.swift (@insert code/explicit-types.swift) 38 | .card (.lang Go ) $ pre.code $ code.go (@insert code/explicit-types.go) 39 | .case (.name "Type Coercion") $ .pair 40 | .card (.lang Swift) $ pre.code $ code.swift (@insert code/type-coercion.swift) 41 | .card (.lang Go ) $ pre.code $ code.go (@insert code/type-coercion.go) 42 | .case (.name "String Interpolation") $ .pair 43 | .card (.lang Swift) $ pre.code $ code.swift (@insert code/string-interpolation.swift) 44 | .card (.lang Go ) $ pre.code $ code.go (@insert code/string-interpolation.go) 45 | .case (.name "Range Operator") $ .pair 46 | .card (.lang Swift) $ pre.code $ code.swift (@insert code/range-operator.swift) 47 | .card (.lang Go ) $ pre.code $ code.go (@insert code/range-operator.go) 48 | .case (.name "Inclusive Range Operator") $ .pair 49 | .card (.lang Swift) $ pre.code $ code.swift (@insert code/inclusive-range-operator.swift) 50 | .card (.lang Go ) $ pre.code $ code.go (@insert code/inclusive-range-operator.go) 51 | 52 | .section 53 | .title COLLECTIONS 54 | .case (.name "Arrays") $ .pair 55 | .card (.lang Swift) $ pre.code $ code.swift (@insert code/arrays.swift) 56 | .card (.lang Go ) $ pre.code $ code.go (@insert code/arrays.go) 57 | .case (.name "Maps") $ .pair 58 | .card (.lang Swift) $ pre.code $ code.swift (@insert code/maps.swift) 59 | .card (.lang Go ) $ pre.code $ code.go (@insert code/maps.go) 60 | .case (.name "Empty Collections") $ .pair 61 | .card (.lang Swift) $ pre.code $ code.swift (@insert code/empty-collections.swift) 62 | .card (.lang Go ) $ pre.code $ code.go (@insert code/empty-collections.go) 63 | 64 | .section 65 | .title FUNCTIONS 66 | .case (.name "Functions") $ .pair 67 | .card (.lang Swift) $ pre.code $ code.swift (@insert code/functions.swift) 68 | .card (.lang Go ) $ pre.code $ code.go (@insert code/functions.go) 69 | .case (.name "Tuple Return") $ .pair 70 | .card (.lang Swift) $ pre.code $ code.swift (@insert code/tuple-return.swift) 71 | .card (.lang Go ) $ pre.code $ code.go (@insert code/tuple-return.go) 72 | .case (.name "Variable Number Of Arguments") $ .pair 73 | .card (.lang Swift) $ pre.code $ code.swift (@insert code/variable-number-of-arguments.swift) 74 | .card (.lang Go ) $ pre.code $ code.go (@insert code/variable-number-of-arguments.go) 75 | .case (.name "Function Type") $ .pair 76 | .card (.lang Swift) $ pre.code $ code.swift (@insert code/function-type.swift) 77 | .card (.lang Go ) $ pre.code $ code.go (@insert code/function-type.go) 78 | .case (.name "Map") $ .pair 79 | .card (.lang Swift) $ pre.code $ code.swift (@insert code/map.swift) 80 | .card (.lang Go ) $ pre.code $ code.go (@insert code/map.go) 81 | .case (.name "Sort") $ .pair 82 | .card (.lang Swift) $ pre.code $ code.swift (@insert code/sort.swift) 83 | .card (.lang Go ) $ pre.code $ code.go (@insert code/sort.go) 84 | .case (.name "Named Arguments") $ .pair 85 | .card (.lang Swift) $ pre.code $ code.swift (@insert code/named-arguments.swift) 86 | .card (.lang Go ) $ pre.code $ code.go (@insert code/named-arguments.go) 87 | .section 88 | .title CLASSES 89 | .case (.name "Declaration") $ .pair 90 | .card (.lang Swift) $ pre.code $ code.swift (@insert code/declaration.swift) 91 | .card (.lang Go ) $ pre.code $ code.go (@insert code/declaration.go) 92 | .case (.name "Usage") $ .pair 93 | .card (.lang Swift) $ pre.code $ code.swift (@insert code/usage.swift) 94 | .card (.lang Go ) $ pre.code $ code.go (@insert code/usage.go) 95 | .case (.name "Subclass") $ .pair 96 | .card (.lang Swift) $ pre.code $ code.swift (@insert code/subclass.swift) 97 | .card (.lang Go ) $ pre.code $ code.go (@insert code/subclass.go) 98 | .case (.name "Checking Type") $ .pair 99 | .card (.lang Swift) $ pre.code $ code.swift (@insert code/checking-type.swift) 100 | .card (.lang Go ) $ pre.code $ code.go (@insert code/checking-type.go) 101 | .case (.name "Downcasting") $ .pair 102 | .card (.lang Swift) $ pre.code $ code.swift (@insert code/downcasting.swift) 103 | .card (.lang Go ) $ pre.code $ code.go (@insert code/downcasting.go) 104 | .case (.name "Protocol") $ .pair 105 | .card (.lang Swift) $ pre.code $ code.swift (@insert code/protocol.swift) 106 | .card (.lang Go ) $ pre.code $ code.go (@insert code/protocol.go) 107 | .case (.name "Extensions") $ .pair 108 | .card (.lang Swift) $ pre.code $ code.swift (@insert code/extensions.swift) 109 | .card (.lang Go ) $ pre.code $ code.go (@insert code/extensions.go) -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "swift-is-like-go", 3 | "version": "0.0.2", 4 | "description": "Swift is like Go ------", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "build": "coffee tasks/render.coffee", 9 | "up": "bash tasks/rsync.sh" 10 | }, 11 | "author": "jiyinyiyong", 12 | "license": "MIT", 13 | "devDependencies": { 14 | "cirru-html": "^0.2.2", 15 | "coffee-script": "^1.12.6" 16 | }, 17 | "dependencies": {}, 18 | "repository": { 19 | "type": "git", 20 | "url": "https://github.com/jiyinyiyong/swift-is-like-go.git" 21 | }, 22 | "keywords": [ 23 | "swift", 24 | "golang" 25 | ], 26 | "bugs": { 27 | "url": "https://github.com/jiyinyiyong/swift-is-like-go/issues" 28 | }, 29 | "homepage": "https://github.com/jiyinyiyong/swift-is-like-go" 30 | } 31 | -------------------------------------------------------------------------------- /tasks/render.coffee: -------------------------------------------------------------------------------- 1 | 2 | fs = require 'fs' 3 | path = require 'path' 4 | 5 | cirruHtml = require 'cirru-html' 6 | 7 | cirruHtml.setResolver (basePath, child, scope) -> 8 | dest = path.join (path.dirname basePath), child 9 | scope?['@filename'] = dest 10 | fs.readFileSync dest, 'utf8' 11 | 12 | main = -> 13 | script = fs.readFileSync (path.join __dirname, '../index.cirru'), 'utf8' 14 | # index.cirru shoud base PWD, i.e. project root 15 | html = cirruHtml.render script, {'@filename': 'index.cirru'} 16 | fs.writeFileSync (path.join __dirname, '../build/index.html'), html 17 | console.log 'Wrote to build/index.html' 18 | 19 | main() 20 | -------------------------------------------------------------------------------- /tasks/rsync.sh: -------------------------------------------------------------------------------- 1 | 2 | rsync -r build/index.html "repo.tiye.me:repo/jiyinyiyong/swift-is-like-go/" 3 | -------------------------------------------------------------------------------- /yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | cirru-html@^0.2.2: 6 | version "0.2.2" 7 | resolved "https://registry.yarnpkg.com/cirru-html/-/cirru-html-0.2.2.tgz#a5f031057f5ac09f040f81ff6d49eb00f1930199" 8 | dependencies: 9 | cirru-parser "^0.9.0-1" 10 | 11 | cirru-parser@^0.9.0-1: 12 | version "0.9.1" 13 | resolved "https://registry.yarnpkg.com/cirru-parser/-/cirru-parser-0.9.1.tgz#8b427e250a1a3ab4bb462fec5d81558e57fc0bae" 14 | 15 | coffee-script@^1.12.6: 16 | version "1.12.6" 17 | resolved "https://registry.yarnpkg.com/coffee-script/-/coffee-script-1.12.6.tgz#285a3f7115689065064d6bf9ef4572db66695cbf" 18 | --------------------------------------------------------------------------------