%new & 的目的是什么? %班级?

发布于 2024-11-25 06:15:04 字数 165 浏览 9 评论 0原文

就 MobileSubstrate 调整而言,%new 和 %class 意味着什么?例如:

%class TPBottomLockBar;

抱歉

%new(v@:)

有双重问题!

What do %new and %class mean in terms of MobileSubstrate tweaks? For instance:

%class TPBottomLockBar;

and

%new(v@:)

Sorry for double question!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

断舍离 2024-12-02 06:15:04

这些都是逻各斯的构造。 %new用于在运行时向类添加新方法,其语法为%new(typeencoding);您可以在 Apple 的 Objective-C 运行时获取有关 Objective-C 类型编码的信息文档。请注意,这些方法的前两个参数始终是 id 和 SEL,因此类型编码的后两个字符必须是“@:”。第一个字符是返回类型,其他任何字符都是您的自定义参数集。

作为一个例子,这里有一个非常无用的方法:(

%hook NSMutableString
%new(v@:)
- (void)appendAwesomeThings {
    [self appendString:@"Awesome."];
}
%end

这实际上可能不起作用,因为 NSString 是一个类簇,但它同样可以作为一个例子!)

%class 是一个已弃用的指令用于前向声明要在运行时使用的类;它已被替换为 %c(ClassName),它将内联使用。
例如,

[[%c(NSString) alloc] initWithString:@"Cool."];

These are both Logos constructs. %new is for adding new methods to a class at runtime, and its syntax is %new(typeencoding); you can get information on Objective-C type encodings in Apple's Objective-C runtime documentation. Note that the first two arguments to these methods are always id and SEL, so the second two characters of your type encoding have to be "@:". The first character is the return type, and anything else is your set of custom arguments.

As an example, here is a pretty un-useful method:

%hook NSMutableString
%new(v@:)
- (void)appendAwesomeThings {
    [self appendString:@"Awesome."];
}
%end

(this will actually probably not work as NSString is a class cluster, but it serves as an example no less!)

%class is a deprecated directive for forward-declaring a class to be used at runtime; It's been replaced with %c(ClassName), which is to be used inline.
For example,

[[%c(NSString) alloc] initWithString:@"Cool."];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文