title: Error: Instance method 'onReceive(_:perform:)' requires that 'Int' conform to 'Publisher'
body: <p>I currently have a <code>Text()</code> which changes based on a 10 minute timer (<code>600 seconds</code>), in the format <code>9:59</code>, <code>9:58</code> etc.</p>
  <p>The below code was working, however now I'm facing a problem. I wanted to perform an action at <code>540 seconds</code> (<code>9:00</code>), so I added:</p>
  <pre><code>if self.countdown.secondsLeft &lt;= 540 &amp;&amp; !codeSent {
      self.codeSent = true
  }
  </code></pre>
  <p>however that gives the following error:</p>
  <pre><code>Modifying state during view update, this will cause undefined behavior.
  </code></pre>
  <p>So instead, I wanted to add the seconds left in my <code>onReceive(self.countdown.secondsLeft)</code> method as seen below - but swift doesn't accept <code>self.countdown.secondsLeft</code> as it's not a <code>@Published</code> <code>Int</code>:</p>
  <pre><code>Instance method 'onReceive(_:perform:)' requires that 'Int' conform to 'Publisher'
  </code></pre>
  <p>However, it is.</p>
  <p>My code is below:</p>
  <p><strong>HomeView.swift</strong></p>
  <pre><code>struct HomeView: View {
      @ObservedObject var waitingCountdown = CountDown(secondsLeft: 600)
  
      var body: some View {
              ZStack {
                  WaitingTimer(countdown: self.waitingCountdown)
              }
      }
  </code></pre>
  <p><strong>WaitingTimer.swift</strong></p>
  <pre><code>struct WaitingTimer: View {
      @ObservedObject var countdown: CountDown
      @State var codeSent = false
      var body: some View {
          VStack{
              Text(&quot;\(timerText())&quot;)
                  .font(.system(size: 28))
                  .fontWeight(.bold)
                  .foregroundColor(Color(&quot;Exit&quot;))
                  .frame(width: 80, height: 40)
                  .padding(EdgeInsets(top: 3, leading: 10, bottom: 3, trailing: 10))
                  .background(
                      Capsule()
                          .fill(Color.white)
                          .opacity(0.7)
                  )
                  .overlay(
                      Capsule()
                          .stroke(Color(&quot;Exit&quot;), lineWidth: 2)
                  )
                  .onReceive(self.countdown.secondsLeft){
                      
                  }
                  .onAppear{
                      print(&quot;Start countdown&quot;)
                      self.countdown.start()
                  }
                  .onDisappear {
                      self.countdown.stop()
                  }
  
          }.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .topLeading)
          .padding(.top, 30)
          .padding(.leading, 30)
      }
      
      func timerText() -&gt; String{
          print(&quot;seconds left: \(self.countdown.secondsLeft) | codeSent: \(codeSent)&quot;)
          let minutes = Int( floor(Double(self.countdown.secondsLeft) / 60) )
          let _seconds = (self.countdown.secondsLeft) - (minutes * 60)
          if self.countdown.secondsLeft &lt;= 540 &amp;&amp; !codeSent {
              print(&quot;SECONDS LEFT: \(self.countdown.secondsLeft) | CODESENT: \(codeSent)&quot;)
              self.codeSent = true
          }
          // Show 9:09 instead of 9:9
          let seconds = _seconds &lt; 1 ? &quot;0\(_seconds)&quot; : String(_seconds)
          print(&quot;Minutes \(minutes) Seconds left: \(seconds)&quot;)
          return &quot;\(minutes):\(seconds)&quot;
          
      }
  }
  </code></pre>
  <p><strong>CountDown.swift</strong></p>
  <pre><code>class CountDown: ObservableObject {
      init(secondsLeft: Int){
          self.secondsLeft = secondsLeft
      }
      @Published var secondsLeft: Int
      var timer: Timer?
      func start(){
          print(&quot;start timer: \(self.secondsLeft)&quot;)
          self.timer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true){ _ in
              self.secondsLeft -= 1
          }
      }
      func stop(){
          self.timer?.invalidate()
      
  </code></pre>
  <p>}
  }</p>
  <p>Any idea what the problem is?</p>