pprevalon pprevalon - 2 months ago 6
Swift Question

swift what is the best way to retrieve snap nodes from firebase

How can I retrieve

senderId
from this snapshot.
ChildAdded
must be use and the FirRef below must stay the same.

this is my current func to retrieve the data from firebase

func retrieveInfo(completion: (result: String)->()) {
fireBaseAPI().childRef("version_one/frontEnd/post/\(self.previousViewMessageId)").observeEventType(.ChildAdded, withBlock: {snapshot in



})


This is the snapshot being printed

Snap (postDescription) Description here
Snap (postTitle) What do you need done
Snap (receiverId) RYclS9Qy4vRr6gp8JbfoztSYQnL2
Snap (senderId) niZKOcnoh0cdFpF2K26bxugw1hz1
Snap (status) 0
Snap (messages) {
"-KRqOqd2POJYpCNSSumG" = {
mediaType = TEXT;
senderDisplayName = "";
senderId = niZKOcnoh0cdFpF2K26bxugw1hz1;
text = iPhone;
};
}


What is the best way to retrieve any of the nodes that says Snap

This is the firebase Json

{
"version_one" : {
"frontEnd" : {
"post" : {
"-KRoucvwAs1jBaoNahDP" : {
"messages" : {
"-KRqOqd2POJYpCNSSumG" : {
"mediaType" : "TEXT",
"senderDisplayName" : "",
"senderId" : "niZKOcnoh0cdFpF2K26bxugw1hz1",
"text" : "iPhone"
}
},
"postDescription" : "Description here",
"postTitle" : "What do you need done",
"receiverId" : "RYclS9Qy4vRr6gp8JbfoztSYQnL2",
"senderId" : "niZKOcnoh0cdFpF2K26bxugw1hz1",
"status" : 0
}
},

Answer
func retrieveInfo(completion: (result: String)->()) {
   fireBaseAPI().childRef("version_one/frontEnd/post/\(self.previousViewMessageId)").observeEventType(.ChildAdded, withBlock: {snapshot in
    if let messageDict = snapshot.value in [String:AnyObject]{

                  let senderId = messageDict["senderId"] as! String
              .....


      }

 })