title: How i return the array in Firebase, swift
body: <p>I'm a super beginner at swift.
  these days I have learned how to use firebase in my project.
  Basically, I prefer to make simple and short functions always in order to use it in the main code.
  so I made a function that will return the array value from firebase JSON data.
  But it always shows the empty, not any data.</p>
  <p>Below is apart of my code.</p>
  <pre><code>class FunctionList: NSObject {
      var ref : fatabaseReference!
      var db : Database.database().reference()
  
      func CallInfo() -&gt; (Date:Array&lt;String&gt;, Temper:Array&lt;Float&gt;){
          var _date: [String] = []
          var _temper: [Float] = []
  
          db.child(&quot;Location&quot;).observeSingleEvent(of: .value){ snapshot in
              var call: [String] = []
              do{
                  let data = try JSONSerialization.data(withJSONObject: snapshot.value, option:[])
                  let decoder = JSONDecoder()
                  let _site: [Location] = try decoder.decode([Location].self. from:data)
                  self._site = _site
  
                  if( _site[0].name == &quot;Newyork&quot;){
                      let Target = _site[0].TemperInfo
                      let lastNum:Int = Target.count
                      let startNum:Int = lastNum-5
                      for i in stride(from startNum, to:lastNum, by: +1){
                          _date.append(Target[i].Date)
                          _temper.append(Target[i].Temper)
                      }
                  }
              } catch let error{
                  print(&quot; Error has occurred : \(error.localizeDescription)&quot;)
                  debugPrint(error)
              }
          }
          //for i in stride(from: 0, to:5, by+1){
          //  print(&quot;\(_date[i])    \(_temper[i]) )
          //}
          return(_date, _temper)
      }
  
  struct Location: Codable{
      let id:String
      let name: String
      let TemperInfo: [T_Info]
      var toDictionary: [String: Any]{
          let tInfoArray = TemperInfo.map{$0.toDictionary}
          let dict: [String: Any] = [&quot;id&quot;:id, &quot;name&quot;:name, &quot;TemperInfo&quot;:tInfoArray]
          return dict
      }
      static var id: Int = 0    
  }
  
  struct T_Info: Codable{
      let Date: String
      let Temper: Float
      var toDictionary:[String: Any]{
          let dict: [String: Any] = [&quot;Date&quot;: Date, &quot;Temper&quot;:Temper]
          return dict
      }
  }
  </code></pre>
  <p>I already check the condition of JSON data in my firebase many time.
  there clearly exist the data.
  and I expected the latest 5 days date and temperature via this function.
  But return always &quot;0&quot;. ( I commented out the print line at the above return line of the &quot;CallInfo&quot; function.)</p>
  <p>Am I miss something? or is there a more good way to return the array that I want?</p>
  <p>Really appreciate your help.
  Thanks!</p>