Introduction to Swift

Swift is Apple's modern, fast, and safe programming language for building apps across iOS, macOS, watchOS, and tvOS, introduced in 2014 to replace Objective-C.

Learn Introduction to Swift in our free Swift course — a beginner-friendly interactive lesson with worked examples, a practice exercise and a quick reference.

Part of the free Swift course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.

By the end of this lesson you'll know what Swift is and where it runs, you'll understand print() and comments, and you'll have written and run your very first Swift program.

What You'll Learn in This Lesson

1️⃣ What is Swift (and where does it run)?

Swift is Apple's modern, fast, and safe programming language. Apple introduced it in 2014 to replace the older Objective-C, and it's now how almost every new iPhone, iPad, Mac, Apple Watch, and Apple TV app is built. "Safe" means the language is designed to catch whole classes of mistakes before your program runs, so your apps crash far less often.

So where do you actually write Swift? You have three common homes for it: Xcode (Apple's free, full code editor on the Mac, used to build real apps), Swift Playgrounds (a friendly app on Mac and iPad for learning and experimenting), and free online editors such as swiftfiddle.com or Replit that run in any browser. For this course, an online editor is the quickest way to start — you don't need a Mac yet.

2️⃣ Your first program: print() and comments

Every Swift journey starts with output. The print() function takes whatever you put between its parentheses and shows it in the console. Text goes inside "double quotes" ; numbers don't need quotes. Anything after // is a comment — a note for humans that Swift ignores. Read this worked example, then run it and confirm the output matches.

Now a slightly bigger first program. A let creates a constant — a named value. The real magic is string interpolation : write (name) inside a string and Swift swaps in the value of name . It reads far better than sticking pieces of text together by hand.

3️⃣ Your turn: print and comment

Time to write some code. The program below is almost finished — just fill in the two blanks marked ___ using the // 👉 hints, then run it and check your output against the expected lines.

4️⃣ Your turn: interpolate your own details

One more guided exercise, this time with string interpolation. Fill in the name and age blanks, then run it — the print line already works once your constants exist.

📋 Quick Reference — Swift Basics

No blanks this time — just a brief and an outline to keep you on track. Write it yourself, run it on SwiftFiddle , and check your output against the example in the comments.

Practice quiz

Which function shows a line of text in the Swift console?

  • print("Hi")
  • echo("Hi")
  • log("Hi")
  • write("Hi")

Answer: print("Hi"). print() writes a line to the console.

How do you start a single-line comment in Swift?

  • #
  • //
  • --
  • /*

Answer: //. // begins a single-line comment; Swift ignores the rest of the line.

Which keyword declares a constant in Swift?

  • const
  • var
  • let
  • final

Answer: let. let makes a constant whose value never changes.

How do you drop a value into a string (interpolation)?

  • ${name}
  • {name}
  • %name%
  • \(name)

Answer: \(name). Swift interpolation uses a backslash and parentheses: \(name).

In which year did Apple introduce Swift?

  • 2014
  • 2010
  • 2008
  • 2018

Answer: 2014. Swift was introduced in 2014 to replace Objective-C.

Does Swift require a semicolon at the end of each line?

  • Yes, always
  • No, they are optional
  • Only inside functions
  • Only for print

Answer: No, they are optional. Swift treats a line end as a statement end, so semicolons are optional.

Which is the correct multi-line comment syntax?

  • ### ... ###
  • <!-- ... -->
  • /* ... */

Answer: /* ... */. Swift wraps multi-line comments in /* and */.

Do you need a Mac to start learning Swift?

  • Yes, always
  • Yes, plus an iPhone
  • Only for print()
  • No, free online editors run it in a browser

Answer: No, free online editors run it in a browser. Tools like SwiftFiddle run Swift in the browser; a Mac is only needed to ship apps.

Text in Swift must be wrapped in...

  • Double quotes
  • Single quotes
  • Backticks
  • Angle brackets

Answer: Double quotes. Swift string literals use "double quotes".

What does Swift's 'safe' design goal mean?

  • It encrypts your code
  • It catches whole classes of mistakes before the program runs
  • It runs only on Apple devices
  • It hides your source

Answer: It runs only on Apple devices. Swift catches many errors at compile time, so apps crash less often.