How to read data from firebase, block with doesn't work?How to store and view images on firebase?How to call Objective-C code from SwiftHow to detect tableView cell touched or clicked in swiftUpdate or reload UITableView after completion of delete action on detail viewFirebase 2.0 - Reading data from FIRDataSnapshot not workingTableView not displaying text with JSON data from API callHow to read data from firebaseHow to read data from FireBaseSwift vertical UICollectionView inside UITableViewHow to search in Firebase Database Swift

Why did Spider-Man take a detour to Dorset?

Do dragons smell of lilacs?

Interviewing with an unmentioned 9 months of sick leave taken during a job

Did Voldemort kill his father before finding out about Horcruxes?

How could an animal "smell" carbon monoxide?

How should one refer to knights (& dames) in academic writing?

Advice for paying off student loans and auto loans now that I have my first 'real' job

What happens if there is no space for entry stamp in the passport for US visa?

Is it ethical for a company to ask its employees to move furniture on a weekend?

How could a medieval fortress manage large groups of migrants and travelers?

How Can I Process Untrusted Data Sources Securely?

Why don't commercial aircraft adopt a slightly more seaplane-like design to allow safer ditching in case of emergency?

Can a Resident Assistant Be Told to Ignore a Lawful Order?

Why isn't aluminium involved in biological processes?

How can I find what program is preventing my Mac from going to sleep?

Is this Android phone Android 9.0 or Android 6.0?

Is this artwork (used in a video game) real?

How can I leave a car for someone if we can't meet in person?

Why alcohol had been selected as fuel for the first American space rockets?

What details should I consider before agreeing for part of my salary to be 'retained' by employer?

Construct, in some manner, a four-dimensional "RegionPlot"

How to ask my office to remove the pride decorations without appearing anti-LGBTQ?

What impact would a dragon the size of Asia have on the environment?

If I stood next to a piece of metal heated to a million degrees, but in a perfect vacuum, would I feel hot?



How to read data from firebase, block with doesn't work?


How to store and view images on firebase?How to call Objective-C code from SwiftHow to detect tableView cell touched or clicked in swiftUpdate or reload UITableView after completion of delete action on detail viewFirebase 2.0 - Reading data from FIRDataSnapshot not workingTableView not displaying text with JSON data from API callHow to read data from firebaseHow to read data from FireBaseSwift vertical UICollectionView inside UITableViewHow to search in Firebase Database Swift






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2















I try to read data from firebase. I've made observeSingleEvent, but block "with" not works, why?



I try to debug and I notice that block with doesn't work.
userID has correct ID
and reference also correct



 var ref: DatabaseReference!
var snapData: NSDictionary?
var nameString = [String]()

override func viewDidLoad()
super.viewDidLoad()

ref = Database.database().reference()
loadData()
table.delegate = self
table.dataSource = self
table.register(UITableViewCell.self, forCellReuseIdentifier: "indentifire")
view.addSubview(table)


// Do any additional setup after loading the view.


// ---------------------------------------------------

//loading data from FireBase
func loadData()
let userID = Auth.auth().currentUser?.uid
ref.child("users").child(userID!).observeSingleEvent(of: .value, with: (snapshot) in
self.snapData = snapshot.value as? NSDictionary
)


// delegate
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
var temp = 0
for (_,val) in snapData!
if val as? String == "false"
temp += 1
nameString.append(val as! String)


return temp


func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
let cell = table.dequeueReusableCell(withIdentifier: "indentifire", for: indexPath)
cell.textLabel!.text = nameString[indexPath.row]
return cell
```

this is my database
![photo](https://imgur.com/a/0UzOPJ7









share|improve this question






























    2















    I try to read data from firebase. I've made observeSingleEvent, but block "with" not works, why?



    I try to debug and I notice that block with doesn't work.
    userID has correct ID
    and reference also correct



     var ref: DatabaseReference!
    var snapData: NSDictionary?
    var nameString = [String]()

    override func viewDidLoad()
    super.viewDidLoad()

    ref = Database.database().reference()
    loadData()
    table.delegate = self
    table.dataSource = self
    table.register(UITableViewCell.self, forCellReuseIdentifier: "indentifire")
    view.addSubview(table)


    // Do any additional setup after loading the view.


    // ---------------------------------------------------

    //loading data from FireBase
    func loadData()
    let userID = Auth.auth().currentUser?.uid
    ref.child("users").child(userID!).observeSingleEvent(of: .value, with: (snapshot) in
    self.snapData = snapshot.value as? NSDictionary
    )


    // delegate
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
    var temp = 0
    for (_,val) in snapData!
    if val as? String == "false"
    temp += 1
    nameString.append(val as! String)


    return temp


    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
    let cell = table.dequeueReusableCell(withIdentifier: "indentifire", for: indexPath)
    cell.textLabel!.text = nameString[indexPath.row]
    return cell
    ```

    this is my database
    ![photo](https://imgur.com/a/0UzOPJ7









    share|improve this question


























      2












      2








      2








      I try to read data from firebase. I've made observeSingleEvent, but block "with" not works, why?



      I try to debug and I notice that block with doesn't work.
      userID has correct ID
      and reference also correct



       var ref: DatabaseReference!
      var snapData: NSDictionary?
      var nameString = [String]()

      override func viewDidLoad()
      super.viewDidLoad()

      ref = Database.database().reference()
      loadData()
      table.delegate = self
      table.dataSource = self
      table.register(UITableViewCell.self, forCellReuseIdentifier: "indentifire")
      view.addSubview(table)


      // Do any additional setup after loading the view.


      // ---------------------------------------------------

      //loading data from FireBase
      func loadData()
      let userID = Auth.auth().currentUser?.uid
      ref.child("users").child(userID!).observeSingleEvent(of: .value, with: (snapshot) in
      self.snapData = snapshot.value as? NSDictionary
      )


      // delegate
      func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
      var temp = 0
      for (_,val) in snapData!
      if val as? String == "false"
      temp += 1
      nameString.append(val as! String)


      return temp


      func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
      let cell = table.dequeueReusableCell(withIdentifier: "indentifire", for: indexPath)
      cell.textLabel!.text = nameString[indexPath.row]
      return cell
      ```

      this is my database
      ![photo](https://imgur.com/a/0UzOPJ7









      share|improve this question
















      I try to read data from firebase. I've made observeSingleEvent, but block "with" not works, why?



      I try to debug and I notice that block with doesn't work.
      userID has correct ID
      and reference also correct



       var ref: DatabaseReference!
      var snapData: NSDictionary?
      var nameString = [String]()

      override func viewDidLoad()
      super.viewDidLoad()

      ref = Database.database().reference()
      loadData()
      table.delegate = self
      table.dataSource = self
      table.register(UITableViewCell.self, forCellReuseIdentifier: "indentifire")
      view.addSubview(table)


      // Do any additional setup after loading the view.


      // ---------------------------------------------------

      //loading data from FireBase
      func loadData()
      let userID = Auth.auth().currentUser?.uid
      ref.child("users").child(userID!).observeSingleEvent(of: .value, with: (snapshot) in
      self.snapData = snapshot.value as? NSDictionary
      )


      // delegate
      func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
      var temp = 0
      for (_,val) in snapData!
      if val as? String == "false"
      temp += 1
      nameString.append(val as! String)


      return temp


      func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
      let cell = table.dequeueReusableCell(withIdentifier: "indentifire", for: indexPath)
      cell.textLabel!.text = nameString[indexPath.row]
      return cell
      ```

      this is my database
      ![photo](https://imgur.com/a/0UzOPJ7






      swift firebase firebase-realtime-database






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 26 at 15:59









      jeff porter

      3,84811 gold badges53 silver badges105 bronze badges




      3,84811 gold badges53 silver badges105 bronze badges










      asked Mar 26 at 8:06









      Игорь СорокинИгорь Сорокин

      224 bronze badges




      224 bronze badges






















          1 Answer
          1






          active

          oldest

          votes


















          0














          The database operations work asynchronously. Map the data in loadData and reload the table view



          func loadData() 
          let userID = Auth.auth().currentUser?.uid
          ref.child("users").child(userID!).observeSingleEvent(of: .value, with: (snapshot) in
          if let snapData = snapshot.value as? [String:Any]
          self.nameString = snapData.values.compactMap $0 as? String
          DispatchQueue.main.async
          self.table.reloadData()


          )



          And in numberOfRowsInSection just return the number of items in nameString



          func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int 
          return nameString.count






          share|improve this answer























          • it works, Thank you!

            – Игорь Сорокин
            Mar 26 at 8:32










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55352389%2fhow-to-read-data-from-firebase-block-with-doesnt-work%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          The database operations work asynchronously. Map the data in loadData and reload the table view



          func loadData() 
          let userID = Auth.auth().currentUser?.uid
          ref.child("users").child(userID!).observeSingleEvent(of: .value, with: (snapshot) in
          if let snapData = snapshot.value as? [String:Any]
          self.nameString = snapData.values.compactMap $0 as? String
          DispatchQueue.main.async
          self.table.reloadData()


          )



          And in numberOfRowsInSection just return the number of items in nameString



          func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int 
          return nameString.count






          share|improve this answer























          • it works, Thank you!

            – Игорь Сорокин
            Mar 26 at 8:32















          0














          The database operations work asynchronously. Map the data in loadData and reload the table view



          func loadData() 
          let userID = Auth.auth().currentUser?.uid
          ref.child("users").child(userID!).observeSingleEvent(of: .value, with: (snapshot) in
          if let snapData = snapshot.value as? [String:Any]
          self.nameString = snapData.values.compactMap $0 as? String
          DispatchQueue.main.async
          self.table.reloadData()


          )



          And in numberOfRowsInSection just return the number of items in nameString



          func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int 
          return nameString.count






          share|improve this answer























          • it works, Thank you!

            – Игорь Сорокин
            Mar 26 at 8:32













          0












          0








          0







          The database operations work asynchronously. Map the data in loadData and reload the table view



          func loadData() 
          let userID = Auth.auth().currentUser?.uid
          ref.child("users").child(userID!).observeSingleEvent(of: .value, with: (snapshot) in
          if let snapData = snapshot.value as? [String:Any]
          self.nameString = snapData.values.compactMap $0 as? String
          DispatchQueue.main.async
          self.table.reloadData()


          )



          And in numberOfRowsInSection just return the number of items in nameString



          func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int 
          return nameString.count






          share|improve this answer













          The database operations work asynchronously. Map the data in loadData and reload the table view



          func loadData() 
          let userID = Auth.auth().currentUser?.uid
          ref.child("users").child(userID!).observeSingleEvent(of: .value, with: (snapshot) in
          if let snapData = snapshot.value as? [String:Any]
          self.nameString = snapData.values.compactMap $0 as? String
          DispatchQueue.main.async
          self.table.reloadData()


          )



          And in numberOfRowsInSection just return the number of items in nameString



          func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int 
          return nameString.count







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 26 at 8:15









          vadianvadian

          167k19 gold badges185 silver badges206 bronze badges




          167k19 gold badges185 silver badges206 bronze badges












          • it works, Thank you!

            – Игорь Сорокин
            Mar 26 at 8:32

















          • it works, Thank you!

            – Игорь Сорокин
            Mar 26 at 8:32
















          it works, Thank you!

          – Игорь Сорокин
          Mar 26 at 8:32





          it works, Thank you!

          – Игорь Сорокин
          Mar 26 at 8:32








          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55352389%2fhow-to-read-data-from-firebase-block-with-doesnt-work%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현