Swift Objective-C runtime class naming

前端 未结 2 2001
孤城傲影
孤城傲影 2021-01-06 16:27

I\'ve noticed that a Swift Class is renamed in objective-c runtime. So if I had a class in swift named ViewController and the name of my app was TestRunti

相关标签:
2条回答
  • 2021-01-06 16:50

    The description is build up in the following 3 sections

    1. The description starts with _Tt which stands for target (bundle / app name)
    2. After that you will have one or more letters like C P F which stands for Class, Protocol or Function. These are in reverse order according to the nesting
    3. Then you will get series of numbers plus a name where the number is the length of the name. each of these are for the target, Class, Protocol or Function as specified in the beginning of the description.

    Functions are a special case here. The description will also has some information about the function signature.

    For example you could have a _TtCFCC5MyApp7MyClass10MySubClass6myFuncFS0_FT_T_L_11MySubSubClass

    This would be the description of the MySubSubClass in the following code:

    class MyClass {
       class MySubClass {
         func myFunc() {
           class MySubSubClass {
           }
         }
       }
    }
    

    Here you can find some sample code that will parse that description into easy to use properties and arrays.

    Update: Demangle is now converted to swift. You can find it here: https://github.com/mattgallagher/CwlDemangle/blob/master/CwlDemangle/CwlDemangle.swift

    0 讨论(0)
  • 2021-01-06 16:51

    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").

    0 讨论(0)
提交回复
热议问题