Swift Tutorial

Swift Tutorial – Like a Real Teacher Would Explain It (2026 style)

Lesson 1 – Getting Started – Where do I even write code?

Three realistic choices right now:

Option Do you need a Mac? Best for beginners? Speed to see first result My recommendation
Swift Playgrounds (app) Yes (Mac or iPad) ★★★★★ 20 seconds Best starting point
Online playground No ★★★★ 10 seconds Very good if no Mac
Xcode Yes ★★★ 2–5 minutes After 1–2 weeks
VS Code + Swift Any computer ★★ 10–30 minutes setup Later (scripting)

Today I recommend: Open Swift Playgrounds on Mac/iPad OR go to https://swiftfiddle.com (online, no installation)

Just press the + button → choose Blank playground → and you’re ready.

Let’s write our first line.

Swift

Run it (▶️ button or Cmd+R).

You should see:

text

That’s your first program. 🎉

Lesson 2 – Variables and Constants (the most important first concept)

Think of variables like labeled boxes.

You can put something in the box, and later change what’s inside.

Swift

But sometimes you want a value that should never change — like your birth year, your username, etc.

That’s what let is for:

Swift

Rule most beginners forget:

  • Use letby default
  • Use varonly when you know you will change the value

Bad habit example (very common):

Swift

Better:

Swift

Lesson 3 – Basic Types (what kinds of things can live in boxes)

Type Example values Real-life analogy Most common?
Int 0, -5, 42, 1000000 Number of apples, age, ID Yes
Double 3.14, -0.001, 99.99 Money, height, temperature Yes
Bool true, false Light switch (on/off) Yes
String “hello”, “😺”, “” Text, names, messages Very yes
Character “A”, “🚀”, ” “ Single letter/symbol Rarely

Examples:

Swift

Swift usually guesses the type (type inference) — this is good!

But sometimes you want to be very clear:

Swift

Lesson 4 – Strings – You will use them every day

Swift

Useful things you do with strings all the time:

Swift

Lesson 5 – Doing decisions – if and switch

Swift

Very important tip: Put the most common case first — code is easier to read.

Now — switch (very loved in Swift):

Swift

Modern pattern you will see a lot:

Swift

Lesson 6 – Lists of things → Arrays

Swift

Looping over array (three common ways):

Swift

Lesson 7 – Optionals – The part that confuses everyone at first

Real-life analogy:

Imagine you ask: “Do you have a nickname?”

  • Some people say “yes, it’s Sunny” → has value
  • Some people say “no” → nil (no nickname)

In Swift we write:

Swift

You cannot just use it directly!

Swift

Safe ways (choose these):

Way 1 – if let (most common)

Swift

Modern short version (very popular now):

Swift

Way 2 – default value

Swift

Way 3 – only when 100% sure (dangerous – use rarely)

Swift
Lesson 8 – Functions – Reusing code
Swift

Functions that return something:

Swift

Default values:

Swift

Where are we now?

You already understand ~70% of lines in most beginner/intermediate Swift code!

Checklist:

  • let vs var
  • Basic types (Int, Double, Bool, String)
  • String interpolation + methods
  • if, else, switch
  • Arrays + looping
  • Optionals (?, ??, if let)
  • Functions

Next steps – pick one path:

  1. SwiftUI → make real iPhone/iPad apps (most popular)
  2. Enums + Structs + Protocols → better organize data
  3. Closures → very important modern Swift feature
  4. async/await → modern way to do network, files, delays
  5. Small project → Todo list, quiz game, unit converter…

Which direction would you like to continue with?

Tell me what feels most interesting to you right now 😊

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *