Getting type from mangled name (e.g. "SS" -> Any.Type)

I have an interesting problem where I need to store an Any.Type as a string in an encoded JSON file.

Later, I need to be able to decode this back into the original type, of course storing is as Any.Type, but then I can later cast this to the appropriate type.

I had all but given up on a solution, until I noticed this is very similarly implemented somehow in the new SwiftData framework.

Attribute for example has a property on it called valueTypeName which stores the mangled type name when encoded to JSON. (e.g. Swift.String becomes "SS")

If I then decode the JSON back into Attribute I see the original type can now be type-cast correctly.

I'd love any insights into how this could be achieved? Any support/ideas on this appreciated.

FYI, tried a pure custom type with no conformances and this worked also, so its not limited to SwiftData attribute types AFAICT.

Just as I posted this, I found a lovely bit of API:


These resolve the issue entirely, however since they're underscored, are they safe to use and will they pass AppStore review?

For context, I'm back porting libraries in my SwiftBackports and SwiftUIBackports so users would only be using this in "previous" iOS versions, and so forward compatibility isn't necessary.