@@ -352,20 +352,29 @@ } + (IMP)replaceClassMethod: (SEL)selector withMethodFromClass: (Class)class { + IMP method = [class methodForSelector: selector]; + + if (method == NULL) + @throw [OFInvalidArgumentException exception]; + return class_replaceMethod(object_getClass(self), selector, - [class methodForSelector: selector], + (IMP _Nonnull)method, typeEncodingForSelector(object_getClass(class), selector)); } + (IMP)replaceInstanceMethod: (SEL)selector withMethodFromClass: (Class)class { - return class_replaceMethod(self, selector, - [class instanceMethodForSelector: selector], + IMP method = [class instanceMethodForSelector: selector]; + + if (method == NULL) + @throw [OFInvalidArgumentException exception]; + + return class_replaceMethod(self, selector, (IMP _Nonnull)method, typeEncodingForSelector(class, selector)); } + (void)inheritMethodsFromClass: (Class)class { @@ -454,11 +463,11 @@ } @finally { free(methodList); } #endif - [self inheritMethodsFromClass: [class superclass]]; + [self inheritMethodsFromClass: superclass]; } + (BOOL)resolveClassMethod: (SEL)selector { return NO; @@ -474,11 +483,11 @@ return self; } - (Class)class { - return object_getClass(self); + return (Class _Nonnull)object_getClass(self); } - (Class)superclass { return class_getSuperclass(object_getClass(self));