title: Swift single button handle audio record, pause and resume
body: <p>I am trying to create <code>audio</code> <code>record</code>, <code>pause</code> and <code>resume</code> record with help of <code>AVFoundation</code> Framework. here, I have done record and stop using single <code>button</code> but I want to do single button handle record, pause and resume three functionality. How to do that?</p>
  
  <pre><code>@IBAction func record_click(_ sender: Any) {
  
          // Record, Pause and Resume need to handle here
  
          if let audioRecorder = self.audioRecorder {
              if (audioRecorder.isRecording) {
                  audioRecorder.stop()
                  record_button.setImage(UIImage(named: "play.png"), for: UIControlState.normal)
                  save_bar_button.isEnabled = true
  
              } else {
  
                  audioRecorder.record()
                  recordTimer = Timer.scheduledTimer(timeInterval: 0.1, target:self, selector:#selector(self.updateAudioMeter(timer:)), userInfo:nil, repeats:true)
                  record_button.setImage(UIImage(named: "pause.png"), for: UIControlState.normal)
                  save_bar_button.isEnabled = false
              }
          }
      }
  </code></pre>