%new&%class的目的是什么?

Zig*_*saz 4 iphone objective-c tweak ios

在MobileSubstrate调整方面,%new和%class意味着什么?例如:

%class TPBottomLockBar;
Run Code Online (Sandbox Code Playgroud)

%new(v@:)
Run Code Online (Sandbox Code Playgroud)

对不起双重问题!

Dus*_*ett 16

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

举个例子,这是一个非常有用的方法:

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

(这实际上可能不会起作用,因为NSString是一个类集群,但它不仅仅是一个例子!)

%class是一个不推荐使用的指令,用于正向声明要在运行时使用的类; 它被替换为%c(ClassName),内联使用.例如,

[[%c(NSString) alloc] initWithString:@"Cool."];
Run Code Online (Sandbox Code Playgroud)