title: Firebase what is the proper way to return handle and reference in Swift
body: <p>I am returning <code>DatabaseReference</code> and <code>Databasehandle</code> from my fetch function in order to detach the listener later. However, inside the closure in the <code>guard</code> statement I cannot return <code>(ref, handle)</code> since it's inside the handle definition. The strange thing is that Xcode does not yell at me and compiles fine if I simply put <code>return</code>. Is this correct?</p>
  
  <p>I know I could have <code>DatabaseReference?</code> and <code>Databasehandle?</code> instead and return <code>(nil, nil)</code> in the guard statement. But it makes more sense to me that a reference and a handle should be returned no matter whether the fetch is successful.</p>
  
  <pre><code>func fetchQuestions(completion: @escaping (Question?)-&gt;()) -&gt; (DatabaseReference, DatabaseHandle) 
  {
      let ref = root.child("timeline").child(uid)
      let handle = ref.observe(.childAdded, with: { (snapshot) in
          var question: Question?
          defer { completion(question) }
  
          guard let dict = snapshot.value as? [String: Int] else { 
              return // Is this correct?
          } 
          ...       
      })
      return (ref, handle)
  }
  </code></pre>