What is the purpose of% new &% class?

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

%class TPBottomLockBar; 

and

 %new( v@ :) 

Sorry for the double question!

+4
source share
1 answer

These are both Logos designs. %new designed to add new methods to the class at runtime, and its syntax is %new(typeencoding) ; you can get information about the Objective-C encoding type in the Apple Objective-C documentation. Note that the first two arguments for these methods are always id and SEL, so the two second characters of the encoding of your type must be " @: ". The first character is the return type, and everything else is your set of custom arguments.

As an example, this is a pretty useful method:

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

(actually this probably doesn't work, since NSString is a class cluster, but it serves as an example no less!)

%class - obsolete directive for direct declaration of the class that will be used at runtime; It has been replaced with %c(ClassName) , which should be used inline. For instance,

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

All Articles