Menu
CoddyTech
Course

Swift for Ruby Developers

Move from Ruby to Swift through static types, value semantics, optionals, Unicode, protocols and ARC. Complete 48 multi-file exercises, build a parcel desk and port two complete Ruby programs.

Ruby and Swift side by side

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

  1. Bindings and Mutation

    Ruby local variables can be rebound to objects of different types. Reassigning label to an integer does not change saved. Ruby String objects can be mutable, so replacing a binding and mutating a shared string object are separate operations; this example only…

    Ruby
    1label = "draft"2saved = label3label = 174puts "#{saved} #{label}"
    Swift
    1let saved = "draft"2var label = saved3label = "ready"4print(saved, label)
  2. Strings and Interpolation

    Ruby double-quoted strings interpolate expressions with #{...}. Methods such as start_with? answer text questions directly, and multiplying a string by an integer repeats it. Ruby strings can be mutable objects with an encoding, so object sharing and…

    Ruby
    1done = 32puts "progress=#{done * 25}%"3puts "report.csv".start_with?("report")
    Swift
    1let done = 32print("progress=\(done * 25)%")3print("report.csv".hasPrefix("report"))
  3. Switch and Patterns

    Ruby case/when uses each condition's === behavior, so patterns such as ranges or classes can act differently from simple equality. Multiple when values can share a branch. Case does not automatically fall through to the next branch, and an omitted match can…

    Ruby
    1command = "pause"2case command3when "pause", "stop" then puts "idle"4else puts "running"5end
    Swift
    1let command = "pause"2switch command {3case "pause", "stop": print("idle")4default: print("running")5}
  4. Functions and Labels

    Ruby distinguishes positional and keyword parameters. Times is a required keyword here, and the method's final expression supplies its return value. A Ruby keyword name is the local parameter name, while Swift can give the caller a different external label…

    Ruby
    1def echo(sound, times:)2  sound * times3end4puts echo("ha", times: 3)
    Swift
    1func echo(_ sound: String, times count: Int) -> String {2    return String(repeating: sound, count: count)3}
  5. Dictionaries and Missing Keys

    Ruby Hash#delete removes an entry, while assigning nil preserves a key with a nil value. Fetch can distinguish a missing entry from that present nil. Hashes preserve insertion order, but an alphabetical report still needs sorting; insertion history is a…

    Ruby
    1settings = {"font" => 14, "gap" => 2}2settings.delete("gap")3puts settings.fetch("gap", 8)4puts settings.length
    Swift
    1var settings = ["font": 14, "gap": 2]2settings["gap"] = nil3print(settings["gap"] ?? 8)4print(settings.count)
  6. Structs and Independent Copies

    Ruby Struct creates a class of record-like objects; it is not a Swift value-type struct. Assigning a Struct instance to another local aliases that instance, so changing direction affects both names. Dup can create a shallow separate instance, but referenced…

    Ruby
    1Heading = Struct.new(:direction)2first = Heading.new("north")3second = first4second.direction = "west"5puts "#{first.direction} #{second.direction}"
    Swift
    1struct Heading {2    var direction: String3    mutating func turnWest() { direction = "west" }4}

Syllabus

10 chapters48 lessons1 project48 challenges99 quiz questions

More courses for Ruby developers

Learn Swift from another language

Frequently asked questions

Who is Swift for Ruby Developers for?

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

Do I need to know Swift already?

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

How many lessons does Swift for Ruby Developers have?

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

What does Swift for Ruby Developers cover?

The course is organized into chapters covering: Starting Swift, Text and Decisions, Control Flow, Functions and Arrays, and more.

Is Swift for Ruby 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 Swift for Ruby Developers for free

Get started