Skip to content

Swift Practice (Basics)

Intuition

Learning through practice: Practice problems are like training drills — they help you apply knowledge and identify areas that need more study.

Why it matters: Regular practice builds confidence and reveals patterns in how concepts are tested. Each problem reinforces key programming concepts.

The key insight: Making mistakes during practice is valuable — each error points to a concept that needs clarification.

Swift — Interactive Practice

10 auto-graded practice problems covering core Swift concepts. Select an answer, submit, and review the explanation.


Types and Variables


Optionals


Collections


Closures


OOP and Error Handling

Common Mistakes

Assuming let and var behave like other languages: In Swift, let creates an immutable constant, not a constant-expression. You cannot reassign a let even if the value hasn’t changed yet.

Confusing filter with compactMap: filter keeps or removes elements but doesn’t transform. compactMap transforms and unwraps optionals. Using filter when you need compactMap leaves optionals in the result.

Forgetting @escaping on stored closures: Closures stored in properties or passed to async functions must be marked @escaping. Omitting it causes a compile error because non-escaping closures cannot outlive the function.


Cross-References

  • Swift Basics: Core Swift language features including types, control flow, and functions.
  • Swift Protocols: Protocol-oriented programming and generic constraints.
  • Kotlin Basics: Kotlin comparison for JVM/mobile developers.
  • Dart Basics: Flutter/Dart comparison for cross-platform mobile development.
  • iOS Development: Official Apple Swift documentation and tutorials.