Skip to content

Questions d'entretien : Swift Developer

100 vraies questions avec réponses modèles et explications pour les candidats Swift Developer.

Voir un exemple de CV : Swift Developer

S'entraîner avec des cartes

Répétition espacée · Hunter Pass

Questions

typingprotocols

I use some for one hidden concrete type and any when runtime types may differ.

  • some preserves specialization and static identity.
  • any enables heterogeneous storage through an existential container.
  • Different concrete return types usually require any or erasure.

Pourquoi cette question est posée: The interviewer is evaluating practical middle-level reasoning about opaque and existential API boundaries.

typingprotocolsapi

They preserve type relationships but require generic consumers or erasure at storage boundaries.

  • Use one when each conformer owns a specific input or output type.
  • Generic consumers retain compile-time checks.
  • A narrow erased adapter avoids exposing Any.

Pourquoi cette question est posée: The interviewer is evaluating practical middle-level reasoning about associated-type boundaries.

typingprotocols

I use a wrapper such as AnyProducer<Output> that stays generic over the associated output while erasing the conformer.

  • Its initializer is generic over a producer whose Output matches.
  • Forwarding closures hide the concrete producer from callers.
  • I erase only at storage boundaries because boxing and dispatch add cost.

Pourquoi cette question est posée: The interviewer is evaluating practical middle-level reasoning about type-erasure mechanics and cost.

It lets a generic wrapper conform only when its element provides the required behavior.

  • A wrapper can be Codable only where Element: Codable.
  • The compiler enforces the condition.
  • A constrained extension keeps the base type broadly usable.

Pourquoi cette question est posée: The interviewer is evaluating practical middle-level reasoning about conditional generic API design.

ooptypingprotocols

I compose small capability protocols at the call site.

  • A function requires Clock & Logger only when it uses both.
  • Focused protocols produce small test doubles.
  • I name repeated composition only when it has domain meaning.

Pourquoi cette question est posée: The interviewer is evaluating practical middle-level reasoning about focused protocol composition.

copy-on-write

I store it in a private reference box and copy only before a shared mutation.

  • isKnownUniquelyReferenced permits in-place mutation of a unique box.
  • Every mutating path performs the check.
  • The private box prevents callers breaking value semantics.

Pourquoi cette question est posée: The interviewer is evaluating practical middle-level reasoning about custom CoW correctness.

swift

Their formal access scopes can overlap even when the fields look separate.

  • An inout property may lock write access to the whole value.
  • Reading a sibling can then violate exclusivity.
  • I copy the read value locally or shorten the mutation scope.

Pourquoi cette question est posée: The interviewer is evaluating practical middle-level reasoning about memory exclusivity.

closures

They fit APIs that describe a reusable typed property location.

  • A writable key path lets generic code update one field safely.
  • Key paths compose and can be stored as configuration.
  • Closures fit validation, I/O, or contextual work.

Pourquoi cette question est posée: The interviewer is evaluating practical middle-level reasoning about practical key-path selection.

I reserve it for adapters over a genuinely dynamic or forwarded surface.

  • A key-path subscript keeps static types and autocomplete.
  • A string subscript suits JSON-like data but moves failures to runtime.
  • Explicit domain members remain easier to discover.

Pourquoi cette question est posée: The interviewer is evaluating practical middle-level reasoning about safe dynamic-member use.

swiftproperty-wrappersdesign

I use one only for repeated storage behavior with a clear lifecycle.

  • wrappedValue exposes the domain value.
  • projectedValue offers a deliberate binding or control surface.
  • I do not hide network or throwing work behind assignment.

Pourquoi cette question est posée: The interviewer is evaluating practical middle-level reasoning about property-wrapper transparency.

result-type

It fits a typed tree whose nested initializers would obscure structure.

  • Builder methods map expressions and branches into one component type.
  • Diagnostics should point to the caller expression.
  • A normal initializer remains available for dynamic cases.

Pourquoi cette question est posée: The interviewer is evaluating practical middle-level reasoning about result-builder usability.

swift

I use a macro for a deterministic compile-time transformation that is easier to inspect than repetition.

  • An attached macro can synthesize members or conformances.
  • It must emit source-linked diagnostics.
  • A generic function or wrapper wins when tooling is simpler.

Pourquoi cette question est posée: The interviewer is evaluating practical middle-level reasoning about practical macro selection.

swift

I expose actionable domain cases and retain transport details as underlying context.

  • Unauthorized, rate-limited, and invalid-input remain distinct.
  • URLError and database errors map at module boundaries.
  • Unexpected failures keep diagnostic context while UI text stays safe.

Pourquoi cette question est posée: The interviewer is evaluating practical middle-level reasoning about actionable error contracts.

swiftmodulesinjection

I prefer initializer injection with small protocols because required dependencies remain visible.

  • Production composition creates clients at one boundary.
  • Tests pass focused fakes without global state.
  • Defaults are limited to stable leaf dependencies.

Pourquoi cette question est posée: The interviewer is evaluating practical middle-level reasoning about testable dependency design.

server-sidemodules

I put portable domain logic in a core target and platform integrations in adapters.

  • The core imports neither UI frameworks nor Vapor.
  • URLSession, CLI I/O, and Vapor adapt into common use cases.
  • I split further only for clearer dependency direction or build reuse.

Pourquoi cette question est posée: The interviewer is evaluating practical middle-level reasoning about portable module boundaries.

swiftoptionalsdatabase

I keep the core product independent and put Fluent integration in a separate product.

  • Core consumers avoid compiling Fluent.
  • The adapter target depends on core and the database package.
  • A consumer fixture imports only the core product and builds without Fluent.

Pourquoi cette question est posée: The interviewer is evaluating practical middle-level reasoning about SPM target dependency cost.

swift-package-manager

I declare resources on their owning target and resolve them through Bundle.module.

  • .process transforms supported resources while .copy preserves layout.
  • Lookup belongs in the declaring target.
  • I test installed-package paths, not source-relative paths.

Pourquoi cette question est posée: The interviewer is evaluating practical middle-level reasoning about SPM resource ownership.

swift-package-manager

I add one when a deterministic generator or validator must run with each target build.

  • Declared inputs and outputs enable incremental work.
  • Generated files go to the plugin work directory.
  • Optional formatting belongs in a command plugin.

Pourquoi cette question est posée: The interviewer is evaluating practical middle-level reasoning about SPM plugin behavior.

api

API stability preserves source compatibility, ABI stability preserves binary linking, and module stability lets clients compile against a module built with another compiler version.

  • An API change can break recompilation even when existing binaries still link.
  • A stable ABI defines runtime binary interfaces for compiled clients.
  • A stable .swiftinterface provides module stability for compile-time imports.
  • Library evolution enables resilience so non-frozen layouts and cases may change without recompiling clients.

Pourquoi cette question est posée: The interviewer is evaluating practical middle-level reasoning about library distribution stability.

swiftvalue-types

Clients must tolerate future cases and layout changes unless the type is frozen.

  • External switches over non-frozen enums need @unknown default.
  • A resilient struct can evolve stored layout.
  • I use @frozen only as a long-term contract.

Pourquoi cette question est posée: The interviewer is evaluating practical middle-level reasoning about Swift resilience.

Questions verrouillées

  • 21

    How do you choose closure capture ownership for long async work?

    closuresasyncconcurrency
  • 22

    What costs affect a generic versus existential choice?

    generics
  • 23

    When do you choose async let over a task group?

    asyncconcurrencystructured-concurrency
  • 24

    How would you limit a task group processing 500 files?

    concurrencystructured-concurrency
  • 25

    How should cancellation flow through a reusable async API?

    asyncconcurrencyapi
  • 26

    How do you bridge a single-shot callback with a checked continuation?

    callbacks
  • 27

    How would you expose filesystem events as an AsyncSequence?

    asyncconcurrency
  • 28

    Why can actor state change across an await?

    asyncconcurrency
  • 29

    How do isolated parameters improve actor APIs?

    concurrencyapi
  • 30

    When would you define a custom global actor?

    concurrency
  • 31

    How do you enable Swift 6 strict concurrency in an existing module?

    concurrencyswiftswift-concurrency
  • 32

    What promise does Sendable make for a custom type?

    promisesconcurrency
  • 33

    How would you configure a reusable Foundation networking client?

    config
  • 34

    How do you decode compatible JSON changes without hiding bad data?

  • 35

    How do URLCache and HTTP cache headers share responsibility?

    cachinghttp
  • 36

    What belongs in Vapor middleware?

    middlewareserver-side
  • 37

    How should Vapor Content types differ from Fluent models?

    server-side
  • 38

    How do you fetch parents and filtered children efficiently with Fluent?

  • 39

    How would you design authentication for a small Vapor API?

    designserver-sideapi
  • 40

    When should Fluent writes share a transaction?

    transactions
  • 41

    How do you stream standard input in a cross-platform Swift CLI?

    swift
  • 42

    How do you run a child process and collect output safely?

    concurrency
  • 43

    How should a Swift CLI handle termination signals?

    swift
  • 44

    How do you make a Swift CLI command easy to test?

    swift
  • 45

    How do XCTest and Swift Testing fit into package tests?

    swift-testingxctestswift
  • 46

    Who should own mutable state in a SwiftUI feature?

    swiftuiswift
  • 47

    How do you expose a UIKit controller inside SwiftUI?

    uikitswiftuiswift
  • 48

    How do you pass state between UIKit and embedded SwiftUI?

    uikitswiftuiswift
  • 49

    How do you keep navigation ownership clear in mixed SwiftUI and UIKit?

    uikitswiftuinavigation
  • 50

    How do you design portable file processing for Darwin and Linux?

    designconcurrency
  • 51

    Two concurrent withdrawals both pass an actor balance check, producing a negative balance; how do you fix it?

    concurrency
  • 52

    A search screen still completes old requests after the user leaves; what is missing?

  • 53

    A checked continuation sometimes traps for being resumed twice; how do you debug it?

  • 54

    A user-initiated parent task creates a plain Task; what priority and cancellation behavior should you expect?

    resiliencestructured-concurrency
  • 55

    A Task.detached loses request metadata and runs at an unexpected priority; why?

    structured-concurrency
  • 56

    Swift 6 rejects capturing a mutable cache class in an @Sendable closure; what is the right fix?

    closuresswiftconcurrency
  • 57

    A background callback updates an observable model and Swift 6 reports an isolation error; what do you change?

    callbacksswift
  • 58

    An AsyncStream producer emits 5,000 events per second while the consumer handles 200; how do you bound it?

    asyncconcurrency
  • 59

    A cancelled consumer leaves a socket feeding AsyncStream open; where should cleanup live?

    asyncconcurrency
  • 60

    After enabling Swift 6, a shared metrics dictionary shows data-race diagnostics; how do you migrate it?

    swiftmonitoring
  • 61

    A coordinator and its child controller never deallocate; how do you inspect the ARC graph?

    architecture-patternsmemory
  • 62

    A view model stores a task that captures it and remains alive after dismissal; how do you fix the lifecycle?

    structured-concurrency
  • 63

    Appending one byte to a custom CoW buffer suddenly copies 20 MB repeatedly; what do you inspect?

  • 64

    Profiling shows 12 percent CPU in witness dispatch over [any Rule]; what change do you consider?

    profiling
  • 65

    A generic parser makes the CLI binary 18 MB larger after adding many formats; how do you reduce it?

    generics
  • 66

    A server renamed JSON field display_name to name; how do you decode old cached payloads?

    caching
  • 67

    An API adds an unknown enum string and decoding fails the whole response; what do you change?

    enums
  • 68

    Date decoding passes locally but fails for fractional seconds in production payloads; how do you fix it?

  • 69

    SPM reports a dependency cycle between Domain, Networking, and Feature; how do you break it?

    dependenciesswift-package-managerdependency-graph
  • 70

    An SPM library finds a template in Xcode but not when consumed by another package; what do you check?

    xcodeswift-package-manager
  • 71

    An SPM build plugin runs on every incremental build despite unchanged inputs; how do you debug it?

    swift-package-manager
  • 72

    A package builds on macOS but fails on Linux because a Foundation API is unavailable; what is your approach?

    api
  • 73

    An XCTest async test sleeps 500 ms and fails intermittently on CI; how do you make it deterministic?

    asyncconcurrencytesting
  • 74

    A Swift Testing parameterized test shares a mutable fake and becomes order-dependent; how do you fix it?

    swift-testingswift
  • 75

    A GET request returns 503 twice before succeeding; what retry policy do you implement?

    resilience
  • 76

    A profile response remains stale after an update even though URLCache is enabled; what do you inspect?

  • 77

    Rapid refreshes create three identical URLSession requests; how do you avoid wasted work?

    networking
  • 78

    A Vapor route performs a 300 ms image resize and all requests slow down; what is wrong?

    server-side
  • 79

    Listing 50 authors triggers 51 SQL queries through Fluent; how do you fix it?

    sqlqueries
  • 80

    Creating an order succeeds but decrementing inventory fails; how do you ensure rollback?

    rollback
  • 81

    Vapor requests time out waiting for database connections under modest load; what do you inspect first?

    databaseserver-side
  • 82

    A Vapor error response bypasses access logging after middleware changes; why?

    middlewareserver-sidelogging
  • 83

    A user can fetch another user’s document by changing its ID; authentication passes, so what is missing?

    auth
  • 84

    A Vapor endpoint streams a 2 GB export but memory rises to 2 GB; how do you redesign it?

    server-sideendpointsmemory
  • 85

    A WebSocket client disconnects but its server heartbeat task keeps running; how do you fix it?

    websocketsstructured-concurrency
  • 86

    A Vapor JSON endpoint returns 500 for malformed input; what response design is better?

    designserver-sideendpoints
  • 87

    A CLI reading a pipe grows past 1 GB because no newline arrives; how do you fix it?

  • 88

    A Swift CLI hangs after its child process exits with heavy stderr output; what caused it?

    concurrencyswift
  • 89

    A CLI receives SIGTERM during file conversion and leaves a corrupt destination; how do you shut down?

  • 90

    A CLI test calls exit(2) and terminates the entire test runner; how do you redesign it?

  • 91

    A SwiftUI screen reloads whenever its parent toggles an unrelated flag; why?

    swiftuiswift
  • 92

    A SwiftUI edit sheet mutates the original model even after the user taps Cancel; why, and how do you fix it?

    swiftuiswift
  • 93

    A navigation destination is pushed twice after one SwiftUI action in a UIKit flow; what do you inspect?

    uikitswiftuinavigation
  • 94

    A UIKit coordinator leaks after presenting a SwiftUI hosting controller; where can the cycle be?

    uikitswiftuiswift
  • 95

    A UIViewControllerRepresentable ignores new SwiftUI input after creation; what is missing?

    swiftuiswift
  • 96

    A form embedded in UIKit loses edits when its hosting controller is rebuilt; how do you preserve state?

    formsuikit
  • 97

    Two tasks append to the same file and records interleave; what Foundation design do you use?

    design
  • 98

    Tests in an SPM test target cannot find a JSON fixture; what do you change?

    fixturesswift-package-manager
  • 99

    Two Fluent requests read version 4 and both overwrite a record; how do you prevent the lost update?

  • 100

    A URLSession request is cancelled, but decoding still publishes its result; how do you stop the stale update?

    networkingresult-type