Menu
CoddyTech
Course

Dart for Swift Developers

Move from Swift to standalone Dart through typed functions, null safety, collections, errors and object contracts. Build a four-step parcel depot, use classes, interfaces and mixins, then port two complete Swift programs.

Swift and Dart side by side

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

  1. Output and Comments

    Swift interpolates with a backslash and parentheses. Dart uses dollar-prefixed names or braces in ordinary strings, and a top-level main function supplies the entry point instead of executable top-level statements.

    Swift
    1import Foundation2
    3let lane=3;print("lane:\(lane)")
    Dart
    1void main(){final lane=3;print('lane:$lane');}
  2. Boolean Conditions

    Swift and Dart conditions require Boolean values, not truthiness. Both short-circuit the right operand. Optional Bool and nullable bool still require explicit handling before use as an ordinary condition.

    Swift
    1import Foundation2func probe()->Bool{print("probe");return true}3if false && probe(){print("open")}else{print("closed")}
    Dart
    1bool probe(){print('probe');return true;}2void main(){if(false && probe()){print('open');}else{print('closed');}}
  3. Functions and Returns

    Swift functions distinguish external argument labels and local names. Dart has positional and named parameter categories instead. Dart arrow syntax returns one expression; both languages statically describe non-null results.

    Swift
    1import Foundation2func isLog(_ name:String)->Bool{name.hasSuffix(".log")}3print(isLog("server.log"))
    Dart
    1bool isLog(String name)=>name.endsWith('.log');2void main(){print(isLog('server.log'));}
  4. Iterables and Laziness

    Swift ordinary Array.map is eager, while lazy.map defers work. Dart Iterable.map is lazy by default. Repeated traversals can repeat side effects, so materialize when stable evaluated results are desired.

    Swift
    1import Foundation2
    3let result=[2,3].lazy.map{n in print("visit:\(n)");return n*2};print("made");print(result.first!)
    Dart
    1void main(){final result=[2,3].map((n){print('visit:$n');return n*2;});print('made');print(result.first);}
  5. Parsing and Validation

    Swift Int string initialization returns an Optional, like Dart tryParse returning a nullable value. Do not assume whitespace, hexadecimal or signed syntax is identical; explicit input contracts need explicit validation.

    Swift
    1import Foundation2
    3print(Int("nope").map(String.init) ?? "invalid");print(Int("42")!)
    Dart
    1void main(){print(int.tryParse('nope')??'invalid');print(int.tryParse('42'));}
  6. Classes and Instances

    Swift classes are reference types, unlike Swift structs. Dart ordinary class instances are also reference objects. A let or final binding can point to an object whose methods mutate its internal state.

    Swift
    1import Foundation2class Lamp{var on=false;func toggle(){on = !on}}3let a=Lamp(),b=Lamp();a.toggle();print("\(a.on):\(b.on)")
    Dart
    1class Lamp{bool on=false;void toggle(){on=!on;}}2void main(){final a=Lamp(),b=Lamp();a.toggle();print('${a.on}:${b.on}');}

Syllabus

10 chapters48 lessons1 project48 challenges99 quiz questions

More courses for Swift developers

Learn Dart from another language

Frequently asked questions

Who is Dart for Swift Developers for?

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

Do I need to know Dart already?

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

How many lessons does Dart for Swift Developers have?

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

What does Dart for Swift Developers cover?

The course is organized into chapters covering: First Dart Programs, Flow and Decisions, Functions and Values, Collection Pipelines, and more.

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

Get started