Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
369 views
in Technique[技术] by (71.8m points)

ios - More efficient way to retrieve Firebase Data?

I have a hierarchical set of data that I want to retrieve information from Firebase. Below is how my data looks:enter image description here

However, my issue is this: Upon looking at how the data is structured, when I want to grab the name or object id of an attendee, I have to perform the following code:

func getAttendees(child: NSString, completion: (result: Bool, name: String?, objectID: String?) -> Void){
    var attendeesReference = self.eventsReference.childByAppendingPath((child as String) + "/attendees")

    attendeesReference.observeEventType(FEventType.ChildAdded, withBlock: { (snapshot) -> Void in

        //Get the name/object ID of the attendee one by one--inefficient?
        let name = snapshot.value.objectForKey("name") as? String
        let objectID = snapshot.value.objectForKey("objectID") as? String
        if snapshot != nil {
            println("Name: (name) Object ID: (objectID)")
            completion(result: true, name: name, objectID: objectID)
        }

        }) { (error) -> Void in
            println(error.description)
    }   
}

Now this goes through every attendee child and grabs the name and object id one by one. When the function completes, I store each value into a dictionary. Upon doing so, this function is called multiple times and can be very slow especially when going to/from a database so many times. Is there a more efficient way to do this? I have tried to look into FEeventType.Value but that seems to return everything within the attendees child, when all I really want are the name and objectID of each attendee stored into some sort of dictionary. Any help would be appreciated. Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...