-2

So basically I have a function that connects to Firebase and gets data in the form of a string and returns a string(at least I think).

this question Is very simple and kind of a dumb question but how would I call this method in a different thread or core. Sorry don't really know the terms yet. I am trying.

also, I don't think it returns a String which I need so how would I accomplish that?

also this is not a duplicate because if you look at all these type of questions I have not found one that calls the actual method.

typealias someting = (String?) -> Void
    func getOpposingUsername( _ index: Int, completionHandler: @escaping someting) {
        var opposingUser: String = ""
        self.datRef.child("Bets").child(self.tieBetToUser[index]).observe(.childAdded, with: { snapshot in


            guard let dict = snapshot.value as? [String: AnyHashable] else {
                return
            }

            opposingUser = dict["OpposingUsername"] as! String
            if opposingUser.isEmpty {
                completionHandler(nil)
            } else {
                completionHandler(opposingUser)
            }




        })


    }
AL.
  • 36,815
  • 10
  • 142
  • 281
Devin Tripp
  • 115
  • 13

1 Answers1

0

Changing threads would be something like this DispatchQueue.main.async {your code} here is the documentation on GCD Dispatch.

Here is an example of a function that returns a string,

func stringReturn() -> String {
  let aString = "a string"
  return aString  
}
Ro4ch
  • 850
  • 8
  • 21