iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up

Quiz

Swift track quiz: 10 questions on syntax, optionals, structs, protocols, async.

Swift — track quiz

EXAMPLE
// 10 questions. Pass: >= 7.

// ===== Q1 =====
// What's the difference between let and var?
// A) let is immutable binding; var is mutable
// B) Same; var is just shorthand
// C) let is for constants only at compile time
// D) var is reserved for class members

// ===== Q2 =====
// What does '?' after a type mean?
// A) Optional (might be nil)
// B) Generic placeholder
// C) Asynchronous
// D) Required

// ===== Q3 =====
// What's the difference between struct and class?
// A) struct is value type (copied); class is reference type (shared)
// B) struct cannot have methods
// C) class is faster
// D) struct cannot conform to protocols

// ===== Q4 =====
// What does 'guard let value = x else { return }' do?
// A) Loops while x is nil
// B) Unwraps x if non-nil; otherwise exits the scope
// C) Throws an error
// D) Asynchronously waits

// ===== Q5 =====
// What does '@State' do in SwiftUI?
// A) Persists data across app launches
// B) Stores local view state; triggers re-render on change
// C) Marks a property for the database
// D) Disables a view

// ===== Q6 =====
// Which is correct for async work?
// A) async let pair execution + try await on use
// B) DispatchQueue.async
// C) Thread.detach
// D) None of the above

// ===== Q7 =====
// What does 'Codable' do?
// A) Encrypts the type
// B) Synthesises Encodable + Decodable for JSON / plist serialisation
// C) Generates a unit test
// D) Makes the type Hashable

// ===== Q8 =====
// 'weak self' in a closure prevents:
// A) Memory cycles between the captured self and the closure
// B) Async execution
// C) Override of self
// D) Generic constraints

// ===== Q9 =====
// 'protocol' in Swift defines:
// A) A class that cannot be instantiated
// B) A contract; types conform to it
// C) An enumeration
// D) A C interface

// ===== Q10 =====
// '@MainActor' annotates:
// A) A type / function that must run on the main thread
// B) An animation
// C) The app entry point
// D) Test cases

// ===== Answers =====
// 1. A   2. A   3. A   4. B   5. B   6. A   7. B   8. A   9. B   10. A

// ===== Patterns to internalise =====
// - let by default; var only when needed
// - Optionals are first-class; resolve at boundaries
// - struct + value semantics by default
// - guard let for early extraction
// - async / await with structured concurrency
// - Codable for JSON
// - [weak self] in long-lived closures

Why it matters

Quiz takeaway: let / Optional / struct / guard / @State / async let / Codable / weak self / protocol / @MainActor are the daily reflexes. Master these and Swift stops surprising.

Tip: Tweak the snippet with Try it Yourself », then sit the quiz at the bottom of the page.

Example

Example
// 3 questions per lesson.
Try it Yourself »

Discussion

Loading…