Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI: EmptyView().onAppear {} formally exists, but not called when view is presented?

Tags:

swiftui

SwiftUI:

EmptyView().onAppear {
//Not called
}

onAppear formally exists, but not called when view is presented?

like image 958
Neph Muw Avatar asked Jan 26 '26 23:01

Neph Muw


2 Answers

Just simply add:

Rectangle()
   .hidden()
   .onAppear {
     // TODO: Do something
   }
like image 184
Alfredo Luco G Avatar answered Jan 29 '26 13:01

Alfredo Luco G


Consider EmptyView is just as interface stub (to put something where view is required but at some moment there is nothing to provide). It is in a fact not inserted into view hierarchy, so .onAppear is not called, because nothing appears.

like image 31
Asperi Avatar answered Jan 29 '26 11:01

Asperi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!