How should I define my own instance variables in something like the following code in a tweak? Here myBool
is new. I'm using Theos/Logos with iOS 7.0.4. Is this possible? Can't find anything about it anywhere. I know about MSHookIvar but that only works with existing variables.
@interface SBApplication {
BOOL myBool;
}
- (void)setBadge:(id)arg1;
@end
%hook SBApplication
- (void)setBadge:(id)arg1 {
%orig;
if(myBool == NO){
NSLog(@"myBool is NO");
}
}
%end
No, I don't think you can add ivar to en existing class. There is class_addIvar
function but it doesn't work with existing classes. In your case, SBApplication
already defined so you can't add an ivar into it.
I can suggest very simple solution - static/global (or both) variables. It can be, for example, BOOL
variable if you need just one variable. Or it could be an array of object-variable pairs if you want variable for every class instance. The latter will work just like a class ivar.