Thomas Clayson
Thomas Clayson

Reputation: 29925

Where to put "extra" implementation?

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.

Upvotes: 1

Views: 405

Answers (3)

Eiko
Eiko

Reputation: 25632

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.

Upvotes: 3

Vladimir
Vladimir

Reputation: 170849

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.

Upvotes: 1

Related Questions