Swift Objective-C运行时类命名 [英] Swift Objective-C runtime class naming

查看:137
本文介绍了Swift Objective-C运行时类命名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到一个Swift类在objective-c运行时重命名。所以如果我在swift中有一个名为 ViewController 的类,并且当我执行<$ c时,我的应用程序的名称是 TestRuntime $ c> object_getClass(s​​elf), self ViewController ,我会得到这个: _TtC11TestRuntime14ViewController 。我注意到这种模式或格式: _TtC $$ AppName $$ ClassName $ 是一个随机数。我不知道这些数字是从哪里来的。如果有人可以在运行时命名它的类如何swift命名,这将真正帮助我。

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 TestRuntime when I perform object_getClass(self), self being ViewController, I would get this: _TtC11TestRuntime14ViewController. I've noticed this pattern or format: _TtC$$AppName$$ClassName, $ 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.

推荐答案

随机。它们是以下值的长度。这类似于常见的C ++名称调整,并支持可能在其中有相当任意字符的标识符,而不需要一些新的分隔符。

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.

在这种特殊情况下,它是 _TtC then一个十一个字符模块名称然后模块名称,然后十四个字符类名称和类名称。我假设 C 是类。不确定 Tt (可能是类型)。

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

这篇关于Swift Objective-C运行时类命名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆