ios - In Firebase, retrieved data doesn't get out from the .observeEventType method -


i defined class in project, manage database set in firebase. following i've done class far.

import foundation import firebase  class db{     class func getprim() -> [string]{         var ret = [string]()          let ref = firdatabase.database().reference()          ref.child("bunya1").observeeventtype(firdataeventtype.value, withblock: {             s in              ret = s.value! as! [string]          })          print("ret: \(ret)")         return ret     } } 

and method called in print() method, print(db.getprim()). console(or terminal? anyway screen on bottom of xcode..) says empty array. embraced statement above print("-----------------------").

----------------------- ret: [] [] ----------------------- 2016-09-07 20:23:08.808 이모저모[36962:] <firanalytics/info> created firebase analytics app delegate proxy automatically. disable proxy, set flag firebaseappdelegateproxyenabled no in info.plist 2016-09-07 20:23:08.815 이모저모[36962:] <firanalytics/info> firebase analytics enabled 

seems ret in .observeeventtype() method not take value out of method block. far know data supposed kept.. can give me hint? still don't understand how code block method parameter works. thnx!!

all firebase operations definition asynchronous means program doesn't wait data firebase before going next statement in code. the time print statements called data firebase hasnt been fetched yet.

take @ this answer more information.


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -