Retrieve randomly generated child ID from Firebase

To create a randomly generated key you need to use childByAutoId() (which I can't see in your example code).
This will return a Firebase reference you could use and which will return the key with it's .key property

var post1Ref = ref.childByAutoId()
post1Ref.setValue(post1)

var postId = post1Ref.key

See documentation here


tasksRef.observeSingleEventOfType(.Value, withBlock: { snapshot in
    for task in snapshot.children {
        guard let taskSnapshot = task as? FDataSnapshot else {
            continue
        }

        let id = task.key
        // do other things
    }
}