title: How to implement function like onAppear in SwiftUI?
body: <p>So, I would like to create a custom view and add function. How can I implement a function like <code>.onAppear(perform: (() -&gt; Void)?)</code>? My code does not work, <code>onDismiss</code> closure does not call in the <code>DashboardView</code>.</p>
  
  <pre><code>struct DashboardView: View {
  
    @State var employees = ["Alex", "Olga", "Mark"]
    @State var presentEmployeeView = false
  
    var body: some View {
      NavigationView {
        List {
          Section {
            Button(action: {
              self.presentEmployeeView = true
            }, label: {
              Text("All employees")
            }).buttonStyle(BorderlessButtonStyle())
          }
        }
      }
      .sheet(isPresented: $presentEmployeeView) {
        EmployeesView(employees: self.employees).onDismiss {
          self.presentEmployeeView = false
        }
      }
    }
  }
  
  struct EmployeesView: View {
    let employees: [String]
  
    @State private var onDismissClosure: (() -&gt; Void)? = nil
    func onDismiss(perform action: (() -&gt; Void)? = nil) -&gt; some View {
      self.onDismissClosure = action
      return self
    }
  
    var body: some View {
      NavigationView {
        List {
          ForEach(employees) { employee in
            EmployeeCell(employee: employee)
          }
        }.navigationBarItems(leading:
          Button(action: {
            self.onDismissClosure?()
          }, label: {
            Text("Close")
         })
        )
      }
    }
  }
  </code></pre>