Practice / swift

Swift practice

Every Swift exercise, built from a topic you can open beside it.

68 exercises runs offline
swift Quiz new Which statement about the scope of ARC is accurate? How Swift ARC governs class-instance lifetimes, and how strong, weak, and unowned references prevent or create reference cycles. beginner 1 min · from Automatic reference counting swift Quiz new A cached child may outlive its parent, and callers can handle a missing parent. Which dec… How Swift ARC governs class-instance lifetimes, and how strong, weak, and unowned references prevent or create reference cycles. intermediate 1 min · from Automatic reference counting swift Predict the output new What does this program print? How Swift ARC governs class-instance lifetimes, and how strong, weak, and unowned references prevent or create reference cycles. beginner 2 min · from Automatic reference counting swift Predict the output new What two Boolean values does this program print? How Swift ARC governs class-instance lifetimes, and how strong, weak, and unowned references prevent or create reference cycles. intermediate 2 min · from Automatic reference counting swift Review AI code new Review generated dashboard binding How Swift ARC governs class-instance lifetimes, and how strong, weak, and unowned references prevent or create reference cycles. advanced 6 min · from Automatic reference counting swift Spot the bug new Spot the bug in the object cycle How Swift ARC governs class-instance lifetimes, and how strong, weak, and unowned references prevent or create reference cycles. intermediate 4 min · from Automatic reference counting swift Quiz new Which statement about @escaping is accurate? Understand Swift function values, capture timing, escaping rules, capture lists, and autoclosures, and design callbacks with explicit lifetime and concurrency semantics. beginner 1 min · from Closures swift Predict the output new What does this program print? Understand Swift function values, capture timing, escaping rules, capture lists, and autoclosures, and design callbacks with explicit lifetime and concurrency semantics. intermediate 2 min · from Closures swift Review AI code new Review generated search handler Understand Swift function values, capture timing, escaping rules, capture lists, and autoclosures, and design callbacks with explicit lifetime and concurrency semantics. advanced 6 min · from Closures swift Spot the bug new Spot the bug in the JobQueue Understand Swift function values, capture timing, escaping rules, capture lists, and autoclosures, and design callbacks with explicit lifetime and concurrency semantics. intermediate 4 min · from Closures swift Quiz new Three closures are appended inside for index in 0..<3 and invoked after the loop. Which c… Understand Swift function values, capture timing, escaping rules, capture lists, and autoclosures, and design callbacks with explicit lifetime and concurrency semantics. intermediate 1 min · from Closures swift Quiz new A transport model only consumes server responses and must never be emitted. Which conform… Use Swift's type system to encode and decode data, with precise control over key mapping, missing values, and diagnostic error paths. beginner 1 min · from Codable swift Quiz new Which sequence preserves the distinction between an absent key and an explicit JSON null? Use Swift's type system to encode and decode data, with precise control over key mapping, missing values, and diagnostic error paths. intermediate 1 min · from Codable swift Predict the output new What does this program print? Use Swift's type system to encode and decode data, with precise control over key mapping, missing values, and diagnostic error paths. intermediate 2 min · from Codable swift Review AI code new Review generated order decoder Use Swift's type system to encode and decode data, with precise control over key mapping, missing values, and diagnostic error paths. advanced 6 min · from Codable swift Spot the bug new Spot the bug in the Event decoder Use Swift's type system to encode and decode data, with precise control over key mapping, missing values, and diagnostic error paths. intermediate 4 min · from Codable swift Quiz new Which model correctly stores a different server message in every failure value? Model finite Swift states and use exhaustive patterns to extract associated values, filter cases, and handle type evolution safely. beginner 1 min · from Enums and pattern matching swift Quiz new When is @unknown default preferable to an ordinary default? Model finite Swift states and use exhaustive patterns to extract associated values, filter cases, and handle type evolution safely. advanced 1 min · from Enums and pattern matching swift Predict the output new What does this program print? Model finite Swift states and use exhaustive patterns to extract associated values, filter cases, and handle type evolution safely. beginner 2 min · from Enums and pattern matching swift Review AI code new Review generated order-state update Model finite Swift states and use exhaustive patterns to extract associated values, filter cases, and handle type evolution safely. advanced 6 min · from Enums and pattern matching swift Spot the bug new Spot the bug in the .copying branch Model finite Swift states and use exhaustive patterns to extract associated values, filter cases, and handle type evolution safely. intermediate 4 min · from Enums and pattern matching swift Quiz new When is try? the most accurate API choice? Model recoverable failure with Error, throw, do-catch, typed throws, and Result while preserving useful information at the right boundary. beginner 1 min · from Error handling swift Quiz new What guarantee does throws(ParseError) add to a function declaration? Model recoverable failure with Error, throw, do-catch, typed throws, and Result while preserving useful information at the right boundary. intermediate 1 min · from Error handling swift Predict the output new What does this program print? Model recoverable failure with Error, throw, do-catch, typed throws, and Result while preserving useful information at the right boundary. beginner 2 min · from Error handling swift Review AI code new Review generated order importer Model recoverable failure with Error, throw, do-catch, typed throws, and Result while preserving useful information at the right boundary. advanced 6 min · from Error handling swift Spot the bug new Spot the bug in the profile fallback Model recoverable failure with Error, throw, do-catch, typed throws, and Result while preserving useful information at the right boundary. intermediate 4 min · from Error handling swift Quiz new Which declaration can a Swift extension validly add? Add computed properties, methods, and conformances to existing Swift types without confusing dispatch, storage, or module ownership. beginner 1 min · from Extensions swift Predict the output new What does this program print? Add computed properties, methods, and conformances to existing Swift types without confusing dispatch, storage, or module ownership. intermediate 2 min · from Extensions swift Quiz new What does @retroactive mean on a Swift protocol conformance? Add computed properties, methods, and conformances to existing Swift types without confusing dispatch, storage, or module ownership. advanced 1 min · from Extensions swift Review AI code new Review generated customer extensions Add computed properties, methods, and conformances to existing Swift types without confusing dispatch, storage, or module ownership. advanced 6 min · from Extensions swift Spot the bug new Spot the bug in the safe subscript Add computed properties, methods, and conformances to existing Swift types without confusing dispatch, storage, or module ownership. intermediate 4 min · from Extensions swift Quiz new Which statement about var retryCount = 0 is correct? Swift's static types, immutable and mutable bindings, safe conversions, control flow, functions, collections, and value semantics in working programs. beginner 1 min · from Swift fundamentals swift Quiz new Why does Swift not accept text[0] for a String? Swift's static types, immutable and mutable bindings, safe conversions, control flow, functions, collections, and value semantics in working programs. beginner 1 min · from Swift fundamentals swift Predict the output new What does this program print? Swift's static types, immutable and mutable bindings, safe conversions, control flow, functions, collections, and value semantics in working programs. beginner 2 min · from Swift fundamentals swift Review AI code new Review generated check-in summary Swift's static types, immutable and mutable bindings, safe conversions, control flow, functions, collections, and value semantics in working programs. advanced 6 min · from Swift fundamentals swift Spot the bug new Spot the bug in the region lookup Swift's static types, immutable and mutable bindings, safe conversions, control flow, functions, collections, and value semantics in working programs. intermediate 4 min · from Swift fundamentals swift Predict the output new What does this program print? Use type parameters, constraints, where clauses, and associated types to write reusable Swift while preserving compile-time type relationships. beginner 2 min · from Generics swift Quiz new What does the `Item` in `protocol Catalog<Item>` represent? Use type parameters, constraints, where clauses, and associated types to write reusable Swift while preserving compile-time type relationships. intermediate 1 min · from Generics swift Review AI code new Review generated generic store Use type parameters, constraints, where clauses, and associated types to write reusable Swift while preserving compile-time type relationships. advanced 6 min · from Generics swift Quiz new What does `where Left.Element == Right.Element` require? Use type parameters, constraints, where clauses, and associated types to write reusable Swift while preserving compile-time type relationships. intermediate 1 min · from Generics swift Spot the bug new Spot the bug in the smallest helper Use type parameters, constraints, where clauses, and associated types to write reusable Swift while preserving compile-time type relationships. beginner 4 min · from Generics swift Quiz new Why does input.flatMap { Int($0) } return Int? instead of Int??? Model missing values in the type system and use binding, chaining, coalescing, transformations, and nested optionals without losing meaning. intermediate 1 min · from Optionals swift Quiz new Which statement accurately describes String? in Swift? Model missing values in the type system and use binding, chaining, coalescing, transformations, and nested optionals without losing meaning. beginner 1 min · from Optionals swift Predict the output new Which three states are printed for these dictionary lookups? Model missing values in the type system and use binding, chaining, coalescing, transformations, and nested optionals without losing meaning. intermediate 2 min · from Optionals swift Predict the output new What does this program print? Model missing values in the type system and use binding, chaining, coalescing, transformations, and nested optionals without losing meaning. beginner 2 min · from Optionals swift Review AI code new Review a generated account importer Model missing values in the type system and use binding, chaining, coalescing, transformations, and nested optionals without losing meaning. advanced 8 min · from Optionals swift Spot the bug new Spot the bug in the email lookup Model missing values in the type system and use binding, chaining, coalescing, transformations, and nested optionals without losing meaning. intermediate 4 min · from Optionals swift Quiz new Which statement is correct in Swift 6 language mode? Understand how Swift property wrappers synthesize storage, wrapped and projected values, and how they affect initialization, copying, Codable, and concurrency. advanced 1 min · from Property wrappers swift Predict the output new What does this program print? Understand how Swift property wrappers synthesize storage, wrapped and projected values, and how they affect initialization, copying, Codable, and concurrency. beginner 2 min · from Property wrappers swift Review AI code new Review a generated JSON setting wrapper Understand how Swift property wrappers synthesize storage, wrapped and projected values, and how they affect initialization, copying, Codable, and concurrency. advanced 6 min · from Property wrappers swift Spot the bug new Spot the bug in Atomic increment Understand how Swift property wrappers synthesize storage, wrapped and projected values, and how they affect initialization, copying, Codable, and concurrency. intermediate 4 min · from Property wrappers swift Quiz new For @Rule var score: Int, which synthesized-name description is accurate? Understand how Swift property wrappers synthesize storage, wrapped and projected values, and how they affect initialization, copying, Codable, and concurrency. beginner 1 min · from Property wrappers swift Quiz new Which boundary should hold Circle and Rectangle values in the same array while exposing o… Define capability boundaries with protocols, and understand requirements, conformance, defaults, associated types, some, and any. beginner 1 min · from Protocols swift Predict the output new What does this program print? Define capability boundaries with protocols, and understand requirements, conformance, defaults, associated types, some, and any. intermediate 2 min · from Protocols swift Quiz new What does `var token: String { get }` require from a conforming type? Define capability boundaries with protocols, and understand requirements, conformance, defaults, associated types, some, and any. beginner 1 min · from Protocols swift Review AI code new Review a generated processor registry Define capability boundaries with protocols, and understand requirements, conformance, defaults, associated types, some, and any. advanced 6 min · from Protocols swift Spot the bug new Spot the bug in the Incrementable protocol Define capability boundaries with protocols, and understand requirements, conformance, defaults, associated types, some, and any. beginner 4 min · from Protocols swift Quiz new Who determines the `Item` in a conformance to `protocol Catalog<Item>`? Declare capabilities with Swift protocols, preserve type relationships with generics, and choose associated types, some, and any precisely. intermediate 1 min · from Protocol constraints and existentials swift Quiz new Which form fits a returned value whose implementation chooses one hidden concrete type? Declare capabilities with Swift protocols, preserve type relationships with generics, and choose associated types, some, and any precisely. intermediate 1 min · from Protocol constraints and existentials swift Quiz new Only `sortedValues()` compares a container’s elements. Where should `Element: Comparable`… Declare capabilities with Swift protocols, preserve type relationships with generics, and choose associated types, some, and any precisely. intermediate 1 min · from Protocol constraints and existentials swift Predict the output new What does this program print? Declare capabilities with Swift protocols, preserve type relationships with generics, and choose associated types, some, and any precisely. beginner 2 min · from Protocol constraints and existentials swift Review AI code new Review a generated generic registry Declare capabilities with Swift protocols, preserve type relationships with generics, and choose associated types, some, and any precisely. advanced 6 min · from Protocol constraints and existentials swift Spot the bug new Spot the bug in protocol labeling Declare capabilities with Swift protocols, preserve type relationships with generics, and choose associated types, some, and any precisely. intermediate 4 min · from Protocol constraints and existentials swift Quiz new What does let session = Session() guarantee when Session is a class with mutable properti… Choose Swift structures or classes using value semantics, reference identity, initialization, and copy-on-write without accidental shared state. beginner 1 min · from Structures and classes swift Quiz new How should a public library treat a structure’s synthesized memberwise initializer? Choose Swift structures or classes using value semantics, reference identity, initialization, and copy-on-write without accidental shared state. intermediate 1 min · from Structures and classes swift Predict the output new What does this program print? Choose Swift structures or classes using value semantics, reference identity, initialization, and copy-on-write without accidental shared state. intermediate 2 min · from Structures and classes swift Review AI code new Review generated invoice copy Choose Swift structures or classes using value semantics, reference identity, initialization, and copy-on-write without accidental shared state. advanced 6 min · from Structures and classes swift Spot the bug new Spot the bug in the Counter binding Choose Swift structures or classes using value semantics, reference identity, initialization, and copy-on-write without accidental shared state. beginner 4 min · from Structures and classes