title: Calling functions in the serial queue in Swift
body: <p>I've got a function which is called by observing the <code>NotificationCenter</code>:</p>
  
  <pre><code>NotificationCenter.default.addObserver(self, selector: #selector(observedPosition(_: ), name: "calculatePosition", object: nil)
  </code></pre>
  
  <p>and then the function:</p>
  
  <pre><code>@objc func observedPosition(_ notification: NSNotification) {
     if let data = notification.object as? Int {
        self.sendPosition(from: data)
     }
  </code></pre>
  
  <p>As this function can be called multiple times in very short time periods I would like to add it to the queue and call <code>sendPosition()</code> only once the previous sendPosition() has finished.</p>
  
  <p>I tried something like this but dunno if it's a correct approach:</p>
  
  <pre><code>@objc func observedPosition(_ notification: NSNotification) {
      let queue = DispatchQueue(label: queueLabel, attributes: [], targer: nil)
      queue.sync {
          if let data = notification.object as? Int {
              self.sendPosition(from: data)
          }
      }
  }
  </code></pre>