Convention with categories is to include a prefix when extending Apple classes. For example:
[string XXDataUsingUTF8];
(Yes, it's a stupid example. Just go with it.)
What I'm less clear on is what the convention is when the identifier starts with copy
, set
, init
or new
.
For instance:
[request setHTTPBodyWithKeyValues: keyValues];
If I add my prefix, this no longer follows the "setters start with set" convention.
[request XXSetHTTPBodyWithKeyValues: keyValues];
On the other hand, if I add the prefix after the set, it's no longer really a prefix:
[request setXXHTTPBodyWithKeyValues: keyValues];
This isn't terribly import with set
, but I think it becomes more important with init
, copy
, etc.
Has Apple documented this anywhere? What's in common use?
You could set the method family explicitly in the interface declaration:
@interface NSObject (StevenFisherCategory)
- (NSData *)XXCopyDataUsingUTF8 __attribute__((objc_method_family(copy)));
@end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With