Swift convert any to string. You can also decode into concrete types y...
Swift convert any to string. You can also decode into concrete types you know the shape of. Swift has some nice facilities for working with json. AnyObject can represent an instance of any class type. Unfortunately, mixing these approaches can be tricky. You do have some other options though - either make it a function toLiteral(value: Any) -> String, or what is probably a neater solution; use the description: String attribute which is present on all types that conform to CustomStringConvertible, which includes String, Int, Bool, and Float - your code would be simplified down to just xml. Character represent single-character string like, “2”, “a”, “l”, etc. I've tried to cast like this, but it didn't help: The String(describing:) initializer is the preferred way to convert an instance of any type to a string. Use Any and AnyObject only when you explicitly need the behavior and capabilities they provide. Mar 5, 2018 · TL:DR: Is there any way to unwrap value from v2 after such conversion? : let v1: Any? = "123" let v2: Any = v1 Long story: I have a library which gives me a dictionary with type [String: Any?]. After that, I'm trying to give it to mapping library which expects dictionary with type [String: Any] So at some point when the mapping lib tries to get values if fails because it can't understand that Jul 23, 2018 · It seems like you can't add extensions to Any. txeyl dsu zdnun obc qxhelo amgzmkvz xtzrz tngsvl ndsog lnagc