proomt

Search

Search posts, papers, and topics

All posts

Swift by Sundell3 min readintermediate

Why Swift is introducing a warning for weak captures within nested closures

Summary

Swift 6.4 adds a compiler warning when a nested closure captures `self` weakly while the outer closure implicitly captures `self` strongly. The warning surfaces a hidden retain‑cycle caused by the outer closure’s implicit strong capture, and the article shows three ways to fix or silence it: move the weak capture to the outer closure, add a second weak capture inside the inner closure, or explici…

  • In Swift ≤ 6.3, a nested `[weak self]` does **not** prevent the outer closure from implicitly capturing `self` strongly, which can create retain cycles (e.g., Timer → self → Timer).
  • Swift 6.4 emits: `'weak' ownership of capture 'self' differs from implicitly‑captured strong reference in outer scope` to flag the mismatch.
  • Fixes:
  • • Move the weak capture to the outer closure if the outer closure doesn’t need `self` (`{ [weak self, service] … }`).

Retain cycles caused by implicit strong captures are subtle and easy to miss, especially with nested asynchronous callbacks. The new warning surfaces the problem at compile time, preventing runtime leaks in UI‑heavy iOS code where timers, tasks, and network callbacks are frequent.

6/10

Related reading

  1. Swift 6.4 Released

    Swift 6.4 adds Swift Build as the default SPM build system, stabilizes Subprocess (1.0), expands C++/Java interop, boosts WebAssembly performance (up to 40×), introduces new language features (optional some/any, @diagnose, module selectors, async defer, cancellation shields), adds non‑copyable array types, SBOM generation, and broader IDE support.

    Lobstersswift.org7 minreleaseHN12663lobste.rs23
  2. Eliminating AI Code Hallucinations with TypeScript Compiler Diagnostics and TDD Loops

    The article shows how to replace raw TypeScript compiler output with a programmatic JSON feedback loop that merges diagnostics and Vitest test failures, feeding the structured data back to an LLM coding agent for self‑correction. It provides concrete code for extracting, enriching, validating, and de‑duplicating errors, and demonstrates token savings and deterministic iteration until compilation…

    SitePointsitepoint.com15 min
  3. App Hardening: One Obfuscation Pipeline Across Every Port

    Codename One adds a cloud‑side hardening step that runs on the merged JAR before it is split into Android, iOS, JavaScript, and desktop binaries. It can rename symbols, encrypt string literals, and insert opaque‑predicate control‑flow guards at configurable levels (off → standard → aggressive → paranoid). The transforms are selective per platform to avoid breaking optimizers, and a mapping is kep…

    CodeName Onecodenameone.com6 min