How to fix "error: escaping closure captures mutating 'self' parameter" in init()?

There is no way to make this work. self simply does not have a persistent, unique identity for value types that could possibly be captured by an escaping closure. Even if you unwisely find a way to capture a pointer to the place in memory that the self variable is bound to during some specific init call, that value can be moved and/or copied around to different places in memory, immediately making that pointer stale. In fact, copying view values and otherwise taking advantage of the non-identity of self is a significant part of how SwiftUI does some of the things it does.

13 Likes