iosobjective-ctheoscydia-substrate

theos: 'class' may not respond to 'method' [-Werror]


Header:

@interface Prefs
    -(void)initPrefs;
@end

Tweak.xm:

#import "Main.h"

%hook Class

-(void)method_to_override {
    [self initPrefs];

    %orig;
}

%new 

-(void)initPrefs {
    //do some stuff
}

%end

Above is my code, i am trying to add a new method to the class but I'm always getting

'Class' may not respond to 'initPrefs' [-Werror]

Solution

  • You declare the method - (void)initPrefs in Prefs's interface but you try to use it while hooking into Class.

    You should declare your method in the class that uses it :

    @interface Class
    - (void)initPrefs
    @end
    

    (Alternatively, you can also disable this type of error in your Makefile by adding the line YourTweakName_CFLAGS = -Wno-error, but I don't encourage such a thing)