简体   繁体   中英

What is the purpose of %new & %class?

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

%class TPBottomLockBar;

and

%new(v@:)

Sorry for double question!

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."];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM