Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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)
- Host: GitHub
- URL: https://github.com/timac/fb9687147-swiftui-animation-deinit-thread
- Owner: Timac
- Created: 2021-10-08T09:03:56.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-10-08T09:18:33.000Z (over 3 years ago)
- Last Synced: 2024-11-16T13:04:37.495Z (2 months ago)
- Language: Swift
- Size: 4.18 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Dei: DeinitInThread/DeinitInThread.xcodeproj/project.pbxproj
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: AppStatevar 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)
}
}
```