views:

40

answers:

3

Hi there.

Occationaly I see snippets of code creating new methods for objects and such that looks like this:

@implementation UIImage (Extras)

- (void)aMethod:(id)anObject {
  // some functionality
}

@end

Where do I put this code? Do I put it in the class I'm currently writing code for? If so at what point in the code do I need to put this?

Thank you.

+1  A: 

For the sake of simplicity and to keep code clean I usually put class categories in separate files.

But in general I think you just need to declare your category in some header and import it to let compiler know about methods you add. Implementation of those methods can be put in any (implementation) file, but once again I think it is better to keep it in separate place.

Vladimir
+2  A: 

You can put this category code whereever you like. In general, this code should be in a file called UIImage+Extras.m and a matching header file UIImage+Extras.h.

Eiko
Thanks guys... so just add it to those files and import it as normal? :) simple as that? brilliant.
Thomas Clayson