I have a function in Swift that returns Any? value and I would like to cast the result (based on the value type) to Bool, String or Int.
The function is this one:
static func value(forKey: SettingKeys) -> Any? {
return settingManager.settings.filter({$0.key == forKey.rawValue}).first?.value
}
and then when I do:
let printingEnabled = AppSettings().value(forKey:"printingEnabled") as? Int
i get NIL. Without the casting, the value is Optional("1"). Similar when I try casting results to String or Int. Any idea of how I could cast the result to a type of my choosing?
Thank you.