Kyokook Hwang
Kyokook Hwang

Reputation: 2762

Which is better convention among what the delegate method with class prefix or without prefix?

I have been agonizing over which convention is better when deciding a name of delegates of any classes I make. I usually add the application prefix to the head of methods as follows:

@interface HKKHelloWorld <NSObject>
...
@end

@protocol HKKHelloWorldDelegate <NSObject>
- (void)HKKHelloWorld:(HKKHelloWorld *)helloworld didFinishWorkWithIndex:(NSUInteger)index;
@end

In recent, I fall in one decision problem whether adding a prefix is good convention or not.
I believe people in StackOverflow is able to give me advice to make a better convention.

In short, Which is better convention for a delegate of a class?

- (void)HKKHelloWorld:(HKKHelloWorld *)helloworld didFinishWorkWithIndex:(NSUInteger)index;

or

- (void)helloWorld:(HKKHelloWorld *)helloworld didFinishWorkWithIndex:(NSUInteger)index;

Upvotes: 0

Views: 94

Answers (3)

jscs
jscs

Reputation: 64002

You only need to use a prefix when your name might clash with other names. That means class names, which are all in one namespace, methods and categories that you add to someone else's class, and protocols.

Methods inside your own class are in their own namespace and don't require a prefix. It should be left off there.

Upvotes: 4

Tirth
Tirth

Reputation: 7789

Both are syntactically correct but 2nd one is better,

- (void)helloWorld:(HKKHelloWorld *)helloworld didFinishWorkWithIndex:(NSUInteger)index;

above signature is look like same cocoa objective-C coding standard. See this doc.

Upvotes: 3

Ivica M.
Ivica M.

Reputation: 4823

I don't know if one way is fundamentally better than the other, but prefixes can sometimes help a lot with Xcode's autocompletion.

Upvotes: 2

Related Questions