0

What is the best way to structure Firebase data to implement sections in my UITableview. At this time I only have a standard UITableView and I would like to divide it up in sections.

Now I'm writing just writing the data like this:

ref?.child("lists").child(listName).child(itemName).setValue(["added" : timeStamp, "itemName" : itemName, "amount" : itemAmount, "unit" : itemUnit])    

This gives a Firebase structure like this:

 "lists" : {
        "-List1" : {    
          -"Apples" {
            "added" : "9-7-2019 at: 16:58:47",
            "itemName" : "Apples",    
            "amount" : 5,    
            "unit" : Pcs
        },   
          -"Carrots" {
            "added" : "10-7-2019 at: 12:01:22",
            "itemName" : "Carrots",    
            "amount" : 2,    
            "unit" : Pcs
         }    
        }    

So when the user is adding Apples to the list, I would like them to be able to write Fruits in a textfield and then adding the item in that section

How is this best done, and how is this sorted in Swift?

Eccles
  • 394
  • 1
  • 3
  • 13
  • Hi @Eccles, you should create section like your cells. I think this link will work for you -> https://www.ralfebert.de/ios-examples/uikit/uitableviewcontroller/grouping-sections/. – emrcftci Jul 15 '19 at 07:38
  • The question is a bit unclear; the structure of your Firebase is generally driven by the types of queries you want to run against it, not necessarily how it's displayed in a tableView. Also, you want to be able to write 'Fruits' but there's nothing in your structure to indicate 'Fruits'. Also, there's no reason in this case to duplicate the node key as a child node as well - *Apples* can be a key, or a child but it doesn't need to be both. Also, that structure may lead you into trouble long term. Can you clarify your question and provide an example of what your are trying to do? – Jay Jul 15 '19 at 19:10

0 Answers0