2

I have a problem with encoding UIImage to the base64 string using this category.

This is the code:

NSData *imageData = UIImageJPEGRepresentation([UIImage imageNamed:@"myImage.png"], 1.0);
NSString *imageString = [imageData base64EncodedString];

I get this error:

-[NSConcreteData base64EncodedString]: unrecognized selector sent to instance 0x906800 * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSConcreteData base64EncodedString]: unrecognized selector sent to instance 0x906800'

I just cannot figure it out where the problem is? Can anyone help me with this?

Thanks!


UPDATE

I just figured it out. Xcode did not put .m file into Compile Sources und project Build Phases. Why is this happening all the time on Xcode 4.3 ?

Borut Tomazin
  • 8,041
  • 11
  • 78
  • 91
  • 1
    Possible duplicate of http://stackoverflow.com/questions/3998483/objective-c-category-causing-unrecognized-selector ? – Simon Whitaker Apr 23 '12 at 12:28
  • Just double-checking, you have #imported the category into the class you are coding? –  Apr 23 '12 at 12:29
  • Check out this link, you'll find a pretty detailed explanation on this. http://cocoawithlove.com/2009/06/base64-encoding-options-on-mac-and.html – WhiteTiger Apr 23 '12 at 12:56
  • It works. Do you know how to remove newlines in outputted string ? – Borut Tomazin Apr 23 '12 at 13:04
  • I asked the same thing about xcode 4.3. I realized that when adding single files or classes to a project the target checkbox is often empty when you are choosing how to add it. Be sure it is ticked, or you sure will be heh. – borrrden Apr 23 '12 at 14:05
  • Yeah, that was the problem. Checkbox is not checked always and I did not pay attention. Thanks! – Borut Tomazin Apr 24 '12 at 06:21

1 Answers1

1

Xcode did not put .m file into Compile Sources under project Build Phases. This happened cos I was not careful choosing the right target (project/test).

Borut Tomazin
  • 8,041
  • 11
  • 78
  • 91