Protocol Naming in Objective C Protocol Naming in Objective C objective-c objective-c

Protocol Naming in Objective C


I would suggest that in your case it is not necessarily bad to name your protocol and the base class the same thing, as your class is the principal expression of the protocol (such as with NSObject).

From Apple's Coding Guidelines for Cocoa: Code Naming Basics:

Some protocols group a number of unrelated methods (rather than create several separate small protocols). These protocols tend to be associated with a class that is the principal expression of the protocol. In these cases, the convention is to give the protocol the same name as the class. An example of this sort of protocol is the NSObject protocol. This protocol groups methods that you can use to query any object about its position in the class hierarchy, to make it invoke specific methods, and to increment or decrement its reference count. Because the NSObject class provides the primary expression of these methods, the protocol is named after the class.


All covered in Apple's Coding Guidelines For Cocoa in the section Code Naming Basics.

The author states:

Protocols should be named according to how they group behaviors:

Most protocols group related methods that aren’t associated with anyclass in particular. This type of protocol should be named so that theprotocol won’t be confused with a class. A common convention is to usea gerund (“...ing”) form:

NSLocking - Good.

NSLock - Poor (seems like a name for a class).

Some protocols group a number of unrelated methods (rather than createseveral separate small protocols). These protocols tend to beassociated with a class that is the principal expression of theprotocol. In these cases, the convention is to give the protocol thesame name as the class.

An example of this sort of protocol is the NSObject protocol. Thisprotocol groups methods that you can use to query any object about itsposition in the class hierarchy, to make it invoke specific methods,and to increment or decrement its reference count. Because theNSObject class provides the primary expression of these methods, theprotocol is named after the class.


if you will see predefine protocal of uitableview, NSUrlconnection then u will get the name of protocal just like UItabaleviewDelegate and NSUrlconnectionDelegate. ........

Then you can undertand easy which delegate is belong from which class

So u can use your classnameDelegate as protocal name ....thanks