ios - Can't Save Snapshot to Data Model? -
in viewcontroller file, had following code:
self.rootref.child("users/").child("stringkey").observeeventtype(.value, withblock: { snapshot in self.usera.name = snapshot.value!.objectforkey("name") as? string self.usera.urlone = snapshot.value!.objectforkey("urlone") as? string self.usera.urltwo = snapshot.value!.objectforkey("urltwo") as? string }) print(self.usera.name) print(self.usera.urlone) print(self.usera.urltwo)
but reasons unknown me, output empty. when put print statements inside observer event, desired output. why aren't allowed save snapshot data model?
[observeeventtype] processed in background , print commands on main thread. need saving in background thread or use method completion handler
Comments
Post a Comment