0

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.

Fayza Nawaz
  • 2,256
  • 3
  • 26
  • 61
  • control click on `resizedImageByMagick` and see it it takes you to the interface of the catagory file. check and comment plz – Saheb Roy Sep 14 '15 at 05:02
  • @Sehab Roy, In UIImage (ResizeMagick), Method decleration is as: - (UIImage *) resizedImageByMagick: (NSString *) spec; – Fayza Nawaz Sep 14 '15 at 05:41
  • So after control clicking you are getting navigated there. – Saheb Roy Sep 14 '15 at 05:50
  • Do you have any other instance variable in the name of `image` or check if you have copied the catagory classes properly or not, delete them and copy them once again – Saheb Roy Sep 14 '15 at 05:54
  • Yes.. I am able to do this. – Fayza Nawaz Sep 14 '15 at 05:57
  • @Sahed Roy, i've tried with different names of image + have also copied them. But nothing good... FYI: i've copied the library code (of UIImage(ResizeMagick) by using the following steps: BuildPhases -> CopyBundleResources -> tap on + sign -> Add folder – Fayza Nawaz Sep 14 '15 at 06:01
  • Just drag and drop the classes to your navigator and check the tickmark "Copy items if needed" , add it like this – Saheb Roy Sep 14 '15 at 06:03
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/89550/discussion-between-fyza-nawaz-and-saheb-roy). – Fayza Nawaz Sep 14 '15 at 06:03

1 Answers1

1

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

Community
  • 1
  • 1
Fayza Nawaz
  • 2,256
  • 3
  • 26
  • 61