Swift 5 : What’s ‘Escaping closure captures mutating ‘self’ parameter’ and how to fix it

The problem is that ContentView is a struct, which means it’s a value type. You can’t pass that to a closure and mutate it. If you did, nothing would change, because the closure would have its own independent copy of the struct.

Your problem is that you’ve mixed your View and your Model. There can be many, many copies of a given View (every time it’s passed to a function, a copy is made). You wouldn’t want every one of those copies to initiate a request. Instead move this request logic into a Model object and just let the View observe it.

Leave a Comment