Search code examples
iosuiimageobjective-c-category

UIImage+ResizeMagick | NSInvalidArgumentException | iOS | Swift


I'm using "UIImage+ResizeMagick" (iOS api by some developer for resizing image written in obj-c) in my swift project, but facing issues and getting the following error:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImage resizedImageByMagick:]: unrecognized selector sent to instance 0x7fe74c2065c0'

I know this error occurs when that function doesn't exists in that particular class or if we pass wrong parameters while calling the function but i don't think it's the case with my code (if i'm not wrong)

This class is written as: "UIImage(ResizeMagick)" and as per my knowledge it's a category so i can use the methods with every UIImage object. I've imported it in my class as #import "UIImage+ResizeMagick.h" and using it as:

UIImage *image = [UIImage imageNamed:@"validate-icon-tick.png"];
image = [image resizedImageByMagick:@"200x200"];

I'm using multiple libraries in my project that are written in obj-c but i'm using bridging header for this purpose. May be the problem with ResizeMagick is because of extensions vs categories difference in obj-c and swift. Kindly tell me what i'm doing wrong or if is it possible or not. Thanks.


Solution

  • Fixed the issue for using extension (cocopods) in swift.

    I've added #import <UIImage-ResizeMagick/UIImage+ResizeMagick.h> in my bridging header file. In controller i've used the methods of this extension as:

    let image = oldImage.resizedImageByMagick("200x200")

    Extensions vs Categories (in swift and objective-c) are well explained over here:stack overflow post link