
Learn Swift by writing and running real Swift in your browser. Nothing to install. Beta open now, no deadline.
Joined October 2026
- Tweets79
- Following19
- Followers3
- Likes66
Swift tip: reduce folds an array down to one value.
let scores = [10, 20, 30]
let total = scores.reduce(0, +)
// 50
The 0 is the starting total; + adds each score into it.
Practice it in your browser: swiftquest.dev/beta?ref=x
6
Swift tip: filter keeps only the elements that pass your test.
let scores = [42, 88, 67, 95]
let passed = scores.filter { $0 >= 60 }
// [88, 67, 95]
Order stays the same, and scores itself doesn't change.
Practice it in your browser: swiftquest.dev/beta?ref=x
12
Swift tip: ?? gives an optional a default value.
let name = username ?? "Guest"
If username is nil, name is "Guest". Otherwise you get the unwrapped value.
Try it in your browser: swiftquest.dev/beta?ref=x
12
Swift tip: compactMap is map that drops the nils.
let inputs = ["4", "abc", "9"]
let numbers = inputs.compactMap { Int($0) }
// [4, 9]
"abc" can't become an Int, so it's skipped.
Practice it in your browser: swiftquest.dev/beta?ref=x
1
13
Swift tip: map turns every element into something new and gives you a fresh array.
let prices = [3, 5, 8]
let labels = prices.map { "$\($0)" }
// ["$3", "$5", "$8"]
The original array stays untouched.
Practice it in your browser: swiftquest.dev/beta?ref=x
12
Swift tip: defer runs when the scope exits, however it exits.
func load() {
print("start")
defer { print("cleanup") }
print("work")
}
// start, work, cleanup
Handy for closing files or resetting state.
Try it in your browser: swiftquest.dev/beta?ref=x
13
Swift tip: guard let unwraps early and keeps the happy path flat.
func greet(_ name: String?) {
guard let name else { return }
print("Hi, \(name)")
}
After the guard, name is a plain String for the rest of the function.
Try it in your browser: swiftquest.dev/beta?ref=x
11
Swift tip: enum cases can carry data.
enum Shape {
case circle(Double)
case square(Double)
}
switch Shape.circle(2) {
case .circle(let r): print("radius \(r)")
case .square(let s): print("side \(s)")
}
Try it in your browser: swiftquest.dev/beta?ref=x
1
16
Swift tip: a switch has to cover every case.
switch n {
case 0: print("zero")
case 1...9: print("small")
default: print("big")
}
Drop the default and it won't compile. Int has more values than you listed.
Try it in your browser: swiftquest.dev/beta?ref=x
13
Swift tip: ?? gives an optional a fallback value.
let nickname: String? = nil
print(nickname ?? "Guest") // Guest
If nickname has a value you get that, otherwise you get "Guest". No unwrapping needed.
Try it on a real compiler in your browser: swiftquest.dev/beta?ref=x
1
16
Swift tip: two range operators, easy to mix up.
for i in 1...3 { print(i) } // 1 2 3
for i in 1..<3 { print(i) } // 1 2
... includes the end, ..< stops before it. ..< is the one you want for array indices.
Try it on a real compiler in your browser: swiftquest.dev/beta?ref=x
12
Swift tip: structs get copied, classes get shared.
var a = Point(x: 1)
var b = a
b.x = 5
If Point is a struct, a.x stays 1. If it's a class, a.x is 5 too.
Try it on a real compiler in your browser: swiftquest.dev/beta?ref=x
9
Swift tip: use var for something you never change and the compiler says so:
warning: variable 'total' was never mutated; consider changing to 'let' constant
Start with let. Reach for var when you need it.
Try it on a real compiler in your browser: swiftquest.dev/beta?ref=x
11
guard let: check what a function needs up top, leave early if it's missing, keep the real work unindented.
func greet(_ name: String?) {
guard let name else { return }
print("Welcome, \(name)")
}
SwiftQuest drills this on its free second island: swiftquest.dev/beta?ref=x
10
No Mac? You can still learn Swift.
SwiftQuest runs your code on a real Swift 6.4 compiler in the browser, so a Windows PC, Linux machine or Chromebook works. Nothing to install.
The beta's open with no deadline, and testers keep Pro for life: swiftquest.dev/beta?ref=x
10
SwiftUI modifier order trips up a lot of beginners.
.padding().background(.blue) puts blue behind the padding.
.background(.blue).padding() leaves the padding clear.
SwiftQuest's SwiftUI course draws both in the browser. Beta's open, no deadline: swiftquest.dev/beta?ref=x
10
Apple's SwiftUI only runs on Apple's systems, so how do you draw a SwiftUI preview in a browser?
Wrote up how ours works: a stand-in SwiftUI module, #Preview rewritten before compiling, one run that taps every button up front, and layout in the browser.
dev.to/swiftquest/drawing-sw…
12
SwiftUI is now in the SwiftQuest beta, next to the Swift course.
You write the same code you'd write in Xcode: import SwiftUI, a struct with a body, #Preview. It compiles on a real Swift compiler and the screen is drawn beside your code. You can tap its buttons.
1
11
Honest bit: Apple's SwiftUI only runs on Apple's systems, so the preview is our own drawing, checked against the iOS simulator. Close to Xcode, not identical. When you want it on your iPhone, you finish it in Xcode on a Mac.
1
4
No Mac needed to learn. The beta is open with no deadline, you can be approved the same day and start right away, and testers get Pro for life.
swiftquest.dev/beta?ref=x
3