Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/timac/fb9687147-swiftui-animation-deinit-thread

This sample Xcode project demonstrates a SwiftUI issue (FB9687147)
https://github.com/timac/fb9687147-swiftui-animation-deinit-thread

Last synced: 6 days ago
JSON representation

This sample Xcode project demonstrates a SwiftUI issue (FB9687147)

Awesome Lists containing this project

README

        

## Description

This simple Xcode project demonstrates an issue with SwiftUI where a View animation triggers deinit in a thread. This issue has been reported as FB9687147 to Apple.

![](video.mov)

## Steps to Reproduce

- Download the sample Xcode project DeinitInThread
- Open this project in Xcode 13.0
- Compile and run this project on iOS 15.0 on a device or simulator
- Tap on the button `Switch to Sample View`
- Tap on the button `Switch to Content View`

Result: In the Xcode console you will see a warning that the deinit is called in a thread

```
"**** DEINIT running in some thread {number = 8, name = (null)}"
```

## Reproducibility

- This issue can be reproduced with Xcode 13.0 when running on iOS 15.0 on a device or simulator.
- This issue was not yet tested on iOS 15.1 beta.

## Details

- The Xcode project contains 2 SwiftUI views.
- A button lets you switch from one view to the second view with an animation.
- If the view has a viewModel, the `deinit` for the viewModel is called in a thread rather than in the main thread:

```
struct ContentView: View {
@EnvironmentObject var appState: AppState

var body: some View {
VStack(spacing: 0) {
switch appState.contentType {
case .homeScreen:
Button {
appState.contentType = .contact
} label: {
Text("Switch to Sample View")
}
default:
SampleView()
}

}.animation(.default, value: appState.contentType)
}
}
```