Q:

Casting to String and Bool from firebase function

I have a firebase function that returns an object, at first it returned one item within the object that was just a boolean. When it arrives from the .call function within the swift app, it is rather a one or a zero. Which is fine when casting the string to a boolean as it will just turn into true or false. However, adding more values on this object from the Firebase function and trying to cast the string to a string. It seems to break my Bool as well as the String also not being cast down. It seems in the docs that they always cast down to any. I know this is probably a pretty simple question to answer but can't wrap my head around it.
guard let rawTime = (result?.data as? [String: Bool])?["serverTime"] else { return }
print(rawTime)

guard let rawString = (result?.data as? [String: String])?["example"] else { return }
print(rawString)

My object coming from the firebase function is:
Optional({
    example = lala;
    serverTime = 1;
})

A:

Your data contains 1 and lala as values, so it cannot be casted to [String: Bool] or [String: String].
Values of Swift dictionaries should have a same type.
First cast it to [String: Any] and then cast rawTime from Any to Int and rawString from Any to String:

guard
  let rawTime = (result?.data as? [String: Any])?["serverTime"],
  let time = rawTime as? Int
else { return }
print(time)

guard
  let rawString = (result?.data as? [String: Any])?["example"],
  let string = rawString as? String
else { return }
print(string)

