Menu
CoddyTech
Course

Go for Swift Developers

Transfer your Swift experience to Go: typed values, control flow, arrays, slices, functions, methods, interfaces and error handling. Build a tested multi-file order pipeline.

Swift and Go side by side

The same program in Swift and in Go, from the lessons of this course.

  1. Files and the first run

    Swift console programs can execute top-level code in main.swift, while Go executables declare package main and define main. Both compile typed source, but their module and file rules differ. Go files in one directory share package declarations and each file…

    Swift
    1print("Swift console")
    Go
    1package main2import ("fmt")3
    4func main(){fmt.Println("Go", 3)}
  2. If and scoped names

    Swift if let and guard let can unwrap optionals and create scoped bindings. Go instead permits an initializer before an if condition, with scope extending through else branches. A Go initializer does not perform optional unwrapping by itself. Preserve both…

    Swift
    1let n="go".count; if n>1 { print("long") } else { print("short") }
    Go
    1package main2import ("fmt")3
    4func main(){if n := len("go"); n > 1 { fmt.Println("long") } else { fmt.Println("short") }}
  3. Arrays are values

    Swift Array has value semantics, with copy-on-write storage as an optimization; its length is not part of the Array type. Go fixed arrays include length in their type and copy elements on assignment. In both languages, copying an aggregate containing class…

    Swift
    1let a=[3,5]; var b=a; b[0]=9; print(a[0],b[0])
    Go
    1package main2import ("fmt")3
    4func main(){a:=[2]int{3,5}5b:=a6b[0]=97fmt.Println(a[0],b[0])}
  4. Typed function contracts

    Swift functions support argument labels, defaults and overloads. Go has one explicit signature per function name and no default arguments. Swift inout uses an exclusive mutable access contract, whereas Go pointer parameters have different aliasing rules.…

    Swift
    1func isEven(_ n:Int)->Bool { n%2==0 }; print(isEven(6))
    Go
    1package main2import ("fmt")3func IsEven(n int) bool { return n%2==0 }4func main(){fmt.Println(IsEven(6))}
  5. Struct values

    Swift structs and Go structs have value semantics and copy fields on assignment. Swift classes instead preserve identity, while Go uses pointers for shared identity. A copied struct can still reference shared objects through class-valued Swift fields or Go…

    Swift
    1struct Label { var text:String }; let a=Label(text:"old"); var b=a; b.text="new"; print(a.text,b.text)
    Go
    1package main2import ("fmt")3type Label struct { Text string }4func main(){a:=Label{Text:"old"}5b:=a6b.Text="new"7fmt.Println(a.Text,b.Text)}
  6. Errors are returned values

    Swift throwing functions mark failure in their signature and callers use try with do/catch or another handling form. Go normally returns error as an ordinary result. Translate expected failure into that explicit result rather than using panic as a replacement…

    Swift
    1enum InputError:Error { case notPositive }; func positive(_ n:Int)throws->Int { guard n>0 else { throw InputError.notPositive }; return n }; do { _ = try positive(-2) } catch { print("rejected") }
    Go
    1package main2import ("fmt";"errors")3func Positive(n int)(int,error) { if n<=0{return 0,errors.New("not positive")};return n,nil }4func main(){_,e:=Positive(-2)5fmt.Println(e!=nil)}

Syllabus

9 chapters48 lessons1 project48 challenges99 quiz questions

More courses for Swift developers

Learn Go from another language

Frequently asked questions

Who is Go for Swift Developers for?

For people who already write Swift and want to learn Go. Each lesson starts from Swift you know and shows how Go does the same thing, so you skip the beginner basics.

Do I need to know Go already?

No. The course starts with your first Go program. You need Swift basics: variables, conditions, loops, functions and collections.

How many lessons does Go for Swift Developers have?

Go for Swift Developers contains 48 interactive lessons you can complete at your own pace.

What does Go for Swift Developers cover?

The course is organized into chapters covering: Values and expressions, Control flow, Collections, Functions and pointers, and more.

Is Go for Swift Developers free?

Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.

Coddy programming languages illustration

Start Go for Swift Developers for free

Get started