title: How to disable `onAppear` method of a parent View?
body: <p>I'm currently developing an application using SwiftUI.</p>
  <p>I'm trying to make a timer app and I want to know how to disable <code>onApear</code> method of a parent View or any way to solve a problem I have now.</p>
  <p>When I navigate to a detailed view from a parent view(ListView) using <code>Binding</code> value, the <code>onAppear</code> method work, and then the <code>Binding</code> value gets be reset in case of my codes.</p>
  <p>If I don't use a method(<code>func setTimer()</code> in my codes) to initialize ListRow in <code>onAppear</code> the binding values work well, but I can't show the initial time values when I see the first view.</p>
  <p>How cloud I solve this problem?</p>
  <hr />
  <p>Here are the codes:</p>
  <p>TimerApp.swift</p>
  <pre><code>import SwiftUI
  
  @main
  struct TimerApp: App {
      @ObservedObject var timeManager = TimeManager()
  
      var body: some Scene {
          WindowGroup {
              ListTimerView()
                  .environmentObject(timeManager)
          }
      }
  }
  </code></pre>
  <p>TimeManager.swift</p>
  <pre><code>import SwiftUI
  
  class TimeManager: ObservableObject {
      
      @Published var multipleTimers:[MultipleTimer] = [
          MultipleTimer( hourSelection: 0, minSelection: 2, secSelection: 0),
          MultipleTimer( hourSelection: 0, minSelection: 0, secSelection: 30),
          MultipleTimer( hourSelection: 1, minSelection: 30, secSelection: 0)
  
      ]
      
      var timer = Timer.publish(every: 0.05, on: .main, in: .common).autoconnect()
  }
  
  enum TimeFormat {
      case hr
      case min
      case sec
  }
  
  enum TimerStatus {
      case running
      case pause
      case stopped
  }
  
  struct MultipleTimer:Hashable {
      var hourSelection: Int
      var minSelection: Int
      var secSelection: Int
  }
  </code></pre>
  <p>ListTimerView.swift</p>
  <pre><code>import SwiftUI
  
  struct ListTimerView: View {
      @EnvironmentObject var timeManager:TimeManager
      
      @State var isAddSheet = false
      
      var body: some View {
          NavigationView(){
              VStack{
                  ForEach(timeManager.multipleTimers, id:\.self){multipleTimer in
                      ListTimerRow(hourSelection: multipleTimer.hourSelection, minSelection:  multipleTimer.minSelection, secSelection:  multipleTimer.secSelection)
                  }
              }
          }
      }
  }
  </code></pre>
  <p>ListTimerRow.swift</p>
  <pre><code>import SwiftUI
  
  struct ListTimerRow: View {
      
      @EnvironmentObject var timeManager:TimeManager
      
      @State var hourSelection: Int
      @State var minSelection: Int
      @State var secSelection: Int
      
      @State var duration: Double = 0
      @State var maxValue: Double = 0
      
      @State var displayedTimeFormat: TimeFormat = .min
      @State var timerStatus: TimerStatus = .stopped
      
      var body: some View {
          NavigationLink(destination:DetailTimerView(
              hourSelection: $hourSelection, minSelection: $minSelection, secSelection: $secSelection,
              duration:$duration, displayedTimeFormat:$displayedTimeFormat
          )){
              VStack{
                  HStack{
                      Text(self.displayTimer())
                          .font(.title)
                      Spacer()
                      Image(systemName: &quot;stop.circle.fill&quot;)
                          .font(.title)
                          .opacity(self.timerStatus == .stopped ? 0.1 : 1)
                          .onTapGesture {
                              if timerStatus != .stopped {
                                  self.stop()
                              }
                          }
                      Image(systemName: self.timerStatus == .running ? &quot;pause.circle.fill&quot; : &quot;play.circle.fill&quot;)
                          .font(.title)
                          .opacity(self.hourSelection == 0 &amp;&amp; self.minSelection == 0 &amp;&amp; self.secSelection == 0 ? 0.1 : 1)
                          .onTapGesture {
                              if timerStatus == .stopped {
                                  self.setTimer()
                              }
                              if duration != 0 &amp;&amp; timerStatus != .running {
                                  self.start()
                              } else if timerStatus == .running {
                                  self.pause()
                              }
                          }
                  }
                  Divider()
              }
          }
          .padding()
          .onAppear(){
              self.setTimer()
              print(&quot;onAppear checked&quot;)
          }
          .onReceive(timeManager.timer) { _ in
              guard self.timerStatus == .running else { return }
              
              if self.duration &gt; 0 {
                  self.duration -= 0.05
              } else {
                  self.timerStatus = .stopped
              }
          }
      }
      
      
      func setTimer() {
          duration = Double(hourSelection * 3600 + minSelection * 60 + secSelection)
          maxValue = duration
          
          if duration &lt; 60 {
              displayedTimeFormat = .sec
          } else if duration &lt; 3600 {
              displayedTimeFormat = .min
          } else {
              displayedTimeFormat = .hr
          }
      }
      
      func displayTimer() -&gt; String {
          
          let hr = Int(duration) / 3600
          let min = Int(duration) % 3600 / 60
          let sec = Int(duration) % 3600 % 60
          switch displayedTimeFormat {
          case .hr:
              return String(format: &quot;%02d:%02d:%02d&quot;, hr, min, sec)
          case .min:
              return String(format: &quot;%02d:%02d&quot;, min, sec)
          case .sec:
              return String(format: &quot;%02d:%02d&quot;, min, sec)
              
          }
      }
      
      func start() {
          timerStatus = .running
      }
      
      func pause() {
          timerStatus = .pause
      }
      
      func stop() {
          timerStatus = .stopped
          duration = maxValue
      }
  }
  </code></pre>
  <p>DetailTimerView.swift</p>
  <pre><code>import SwiftUI
  
  struct DetailTimerView: View {
      
      @EnvironmentObject var timeManager:TimeManager
      
      @Binding var hourSelection: Int
      @Binding var minSelection: Int
      @Binding var secSelection: Int
      
      @Binding var duration: Double
      
      @Binding var displayedTimeFormat: TimeFormat
      
      var body: some View {
          VStack{
              Text(self.displayTimer())
                  .font(.title)
          }
      }
      
      func displayTimer() -&gt; String {
          
          let hr = Int(duration) / 3600
          let min = Int(duration) % 3600 / 60
          let sec = Int(duration) % 3600 % 60
          
          switch displayedTimeFormat {
          case .hr:
              return String(format: &quot;%02d:%02d:%02d&quot;, hr, min, sec)
          case .min:
              return String(format: &quot;%02d:%02d&quot;, min, sec)
          case .sec:
              return String(format: &quot;%02d:%02d&quot;, min, sec)
          }
      }
  }
  </code></pre>
  <hr />
  <p>Xcode: Version 12.0.1</p>
  <p>iOS: 14.0</p>
  <p>Life Cycle: SwiftUI App</p>