swift - updateChildValues using dictionary or url -


i looking update firebase database atomically, have been using updatechildvalues. however, have experienced behaviour explained.

when add data database using following code, works fine , new objects added json tree under newly generated key beneath either itemownership or itemcategory nodes:

let key = rootref.child("posteditems").childbyautoid().key  let updatelocations = ["itemownership/\(key)" : uid,                        "itemcategory/\(key)" : category                       ]  rootref.updatechildvalues(updatelocations) print("item has been saved!") 

however, if use constants hold dictionaries, like-so:

let key = rootref.child("posteditems").childbyautoid().key  let itemownership = [key : uid] let itemlocation = [key : location]  let updatelocations = ["itemownership" : itemownership,                        "itemcategory" : itemlocation                       ]  rootref.updatechildvalues(updatelocations) print("item has been saved!") 

instead of adding new values under new autogenerated id, new id , value overwrite old id , value, such can never have more 1 key value pair under itemownership or itemcategory node. why happening? thanks

this working design. when updatechildvalues(), doing behind scenes:

for (key, val) in updatedata {    ref.child( key ).set( val );    } 

so need pass lowest level node in key in order replace node.


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -