Skip to content

Instantly share code, notes, and snippets.

@an0
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save an0/a201795b56c0a842b1f5 to your computer and use it in GitHub Desktop.
Save an0/a201795b56c0a842b1f5 to your computer and use it in GitHub Desktop.
NSObject VS NSObjectProtocol

NSObjectProtocol is more general than NSObject and isEqual and hash are defined in NSObjectProtocol. Logically, we should inherit NSObjectProtocol from Equatable and Hashable.

Why not? Why instead extend NSObject to conform to Equatable and Hashable?

The current design causes problems like this:

if obj.delegate == self {

Binary operator '==' cannot be applied to operands of type 'XXXDelegate' and 'XXXDelegate'

because delegates are NSObjectProtocol not NSObject.

The only reason I can think of is if we use the alternative design NSObjectProtocol will become an protocol with Self or associated type requirement. But will it cause any negative effects? What are they?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment