baileyseymour baileyseymour - 1 year ago 64
Swift Question

Swift Objective-C runtime class naming

I've noticed that a Swift Class is renamed in objective-c runtime. So if I had a class in swift named

and the name of my app was
when I perform
, self being
, I would get this:
. I've noticed this pattern or format:
, $ being a random number. I can't figure out where these numbers are coming from. If someone could shed some light on how swift names its classes in the runtime that would really help me.

Answer Source

They're not random. They're the length of the following value. This is similar to common C++ name mangling and supports identifiers that may have fairly arbitrary characters in them without needing some new separator character. It also can make them easier to parse, especially in C.

In this particular case, it's _TtC then "an eleven character module name" then the module name and then "a fourteen character class name" and the class name. I assume C is class. Not sure about Tt (maybe "type").