Swift Objective-C runtime class naming

前端 未结 2 1988
孤城傲影
孤城傲影 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

提交回复
热议问题