Chapter 1: Swift Introduction

What is Swift? (Why Learn It in 2025?)

Swift is Apple’s modern programming language, first released in 2014. It replaced the older Objective-C for building apps on iPhone, iPad, Mac, Apple Watch, Apple TV, and even visionOS (AR/VR).

Why Swift is Great in 2025–2026:

  • Safe — Prevents many common bugs (especially with optionals and concurrency)
  • Fast — Close to C++ speed, but easier to write
  • Modern — Clean syntax, powerful features like async/await, actors, macros
  • Multi-platform — Apple platforms + server-side (Vapor), Linux, Windows, even Android (experimental)
  • Swift 6.2 (latest as of late 2025) focuses on:
    • Easier concurrency (no more data races by default)
    • Better performance tools
    • Improved debugging & build times
    • Great interoperability with C++, Java, etc.

In short: If you want to build beautiful iOS/macOS apps, or even backend APIs, Swift is one of the best choices today.

Chapter 2: How to Start Writing Swift Code Right Now (No Mac Needed)

Option 1 – Best for beginners Download Swift Playgrounds (free on Mac or iPad) → Open → tap +Blank playground

Option 2 – No Mac? Go to https://swiftfiddle.com → paste code → run

Option 3 – Serious learning Install Xcode (free from App Store on Mac) later.

Let’s write your first line:

Swift

Run it → you’ll see:

text

Congratulations — you just ran Swift code!

Chapter 3: Variables & Constants (let vs var)

Think of variables as boxes with labels.

Swift

Golden rule (very important!):

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

Common beginner mistake:

Swift

Better:

Swift

Chapter 4: Basic Data Types

Type Examples Real-life use case
Int 42, -5, 1000000 Age, count, ID
Double 3.14, 1.76, -0.001 Height, price, temperature
Bool true, false Is raining? Is logged in?
String “Hello”, “আমি বাংলা ভালোবাসি” Names, messages, text

Examples:

Swift

Swift usually guesses the type (type inference) — very nice!

Chapter 5: Strings – The Most Used Type

Swift

Useful string methods:

Swift

Chapter 6: Simple Decisions – if & switch

Swift

Switch (very clean in Swift):

Swift

Chapter 7: Arrays – Lists of Things

Swift

With index:

Swift

Chapter 8: Optionals – The “Maybe” Type

This is the most important Swift concept!

Swift

Danger:

Swift

Safe ways:

Swift

Chapter 9: Functions – Reusable Code

Swift

With return:

Swift

Default parameters:

Swift

Summary Table – What You Learned Today

Topic Key Idea Example Code
Variables let vs var let name = “Amit”
Types Int, Double, Bool, String let price = 99.99
Strings Interpolation, methods “\(first) \(last)”
Control Flow if, switch if temp > 30 { … }
Arrays Ordered list fruits.append(“Orange”)
Optionals ?, ??, if let var age: Int?
Functions Reusable blocks func greet(name: String)

Common Mistakes Beginners Make (and How to Avoid)

Mistake Wrong Code Correct Way
Using var everywhere var name = “Rahul” let name = “Rahul”
Force-unwrapping optionals phoneNumber! if let phoneNumber { … }
Forgetting label in function call greet(“Amit”) greet(name: “Amit”)
Ignoring type inference let age: Int = 25 (unnecessary) let age = 25

Homework (Try These!)

  1. Create a playground and print your name, city, and favorite Tagore poem line.
  2. Write a function that takes temperature and returns a message (“Hot”, “Nice”, “Cold”).
  3. Make an array of 5 Bengali sweets and loop through them printing “I like [sweet]!”.
  4. Create an optional variable age: Int? = nil and safely print it using if let and ??.

Paste your code here if you want me to review or fix errors — I’ll help instantly!

Next lesson? We can go to:

  • Enums (powerful in Swift!)
  • Structs (your own data types)
  • First SwiftUI app (make a real button!)
  • Optionals + arrays deeper
  • Or anything you like!

Just say what feels most exciting 😊 Ready for the next chapter?

You may also like...

Leave a Reply

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