Is Swift a reflective language?

Beginner question alert..

I can't find Swift listed as a reflective language. Wouldn't Mirror make it reflective?

Seems like the full definition of reflective requires more than just showing a representation of the instance. Wikipedia suggest reflective also requires the ability to modify things, which seems anathema to the design of Swift.

So, sort of?

1 Like

There's a talk from @Joe_Groff from 2017 that addresses some of your questions. I think this is the most canonical link to the presentation: https://www.skilled.io/u/swiftsummit/swift-s-reflective-underpinnings-joe-groff (If not, I'm sure someone can chime in with the right reference.)

3 Likes

As far as I understand, Swift is capable of reflection it just doesn't expose public API for it yet. Mirror is an old API that exposes a very limited subset of reflection. It doesn't let you mutate value types and you can only reflect instances of types. So yes / no. Swift can (and probably will) be a reflective language but I wouldn't consider it one yet. Definitely not when compared to what kind of hackery dynamically typed languages like PHP can do.