Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 968
Zigsaz Avatar asked Dec 04 '22 21:12

Zigsaz


1 Answers

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."];
like image 144
Dustin Howett Avatar answered Dec 28 '22 10:12

Dustin Howett