@@ -260,14 +260,18 @@ return oldimp; #endif } -+ (IMP)replaceClassMethod: (SEL)selector - withClassMethodFromClass: (Class)class; ++ (IMP)replaceClassMethod: (SEL)selector + withMethodFromClass: (Class)class; { IMP newimp; + + if (![class isSubclassOfClass: self]) + @throw [OFInvalidArgumentException newWithClass: self + selector: _cmd]; #if defined(OF_OBJFW_RUNTIME) newimp = objc_get_class_method(class, selector); #elif defined(OF_APPLE_RUNTIME) newimp = method_getImplementation(class_getClassMethod(class, @@ -312,14 +316,18 @@ return oldimp; #endif } -+ (IMP)replaceInstanceMethod: (SEL)selector - withInstanceMethodFromClass: (Class)class; ++ (IMP)replaceInstanceMethod: (SEL)selector + withMethodFromClass: (Class)class; { IMP newimp; + + if (![class isSubclassOfClass: self]) + @throw [OFInvalidArgumentException newWithClass: self + selector: _cmd]; #if defined(OF_OBJFW_RUNTIME) newimp = objc_get_instance_method(class, selector); #elif defined(OF_APPLE_RUNTIME) newimp = class_getMethodImplementation(class, selector);