IntrepidPursuits / objective-c-style-guide

MIT License
4 stars 0 forks source link

Feedback CB: Disagreement over naming of methods within categories #5

Closed cprime closed 9 years ago

cprime commented 9 years ago

• The “Categories” is unclear. I assume the convention is supposed to not just be “prefix with your project class prefix” but more specifically: lowercase prefix plus underscore. I’m also have some concerns about a convention like this. It will have an impact on how easily we can share code between projects. Obviously for colors we won’t be sharing them, but what about something like MarkD’s UIView+CircleMask category in Qup? I think I’d rather enforce good, specific naming of methods to avoid collisions. In fact, if I end up with a naming conflict I’d rather know about it than have likely duplicate code sitting around with two different names. I can always choose to prefix in the case of a collision as a solution to the collision.

Benuuu commented 9 years ago

IIRC Xcode doesn't point out collisions and it will compile fine. Behavior will be determined by file compile order and you won't know which is being used until it has a runtime error.

cprime commented 9 years ago

Our decision here is based on this Apple recommended standard: https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/CustomizingExistingClasses/CustomizingExistingClasses.html#//apple_ref/doc/uid/TP40011210-CH6-SW4

colinbrash commented 9 years ago

You are right, Ben, I just checked.  I mistakenly thought they generated warnings.  Too bad they don’t… :(

Colden, thanks.  FYI though, that documentation explicitly states categories “on framework classes.”  So you may want to be explicit about that in our style guide to that as well?  (It does seem silly to prefix on your own classes — every category method on that class would have the same prefix and it wouldn’t help avoid collisions!)

cprime commented 9 years ago

How about something more like this:

Categories

When creating categories on classes not owned by you, category methods should be prefixed with your project class prefix in order to avoid method signature collisions with the original class or a another category on the same class (or even a superclass):

@interface UIColor (INTAdditions)
+ (UIColor *)int_navigationBarColor;
@end

Customizing Existing Classes