Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The onAppear function of SwiftUI may be called two times because SwiftUI is a declarative framework that updates the view hierarchy automatically when a state or property value changes. This means that when the view is rendered or re-rendered, the onAppear function is called. Additionally, the onAppear function can also be called when the view is presented or pushed onto the view stack, causing it to appear on the screen. Therefore, the onAppear function may be called multiple times depending on the state of the view hierarchy, and it's important to consider this behavior when designing and implementing SwiftUI views.