Adam Lee
Adam Lee

Reputation: 25748

In Xcode, how do I know which class implement a protocol?

I am wondering in Xcode, can I quickly know which classes implement some protocols?

I don't want to use search, but want to quickly identify such classes.

Upvotes: 17

Views: 3996

Answers (2)

Dafda
Dafda

Reputation: 202

in particular class in which protocol implement just press 'command btn + right click of mouse' on protocol method..

it will show list of all class with implementation of this method. and you can jump on that class by just click on it...

Upvotes: 10

Sebastian
Sebastian

Reputation: 7720

You can use the Assistant Editor:

  • Open the protocol that you are interested in, place the cursor inside the @protocol definition
  • Open the Assistant Edior (command-option-return) and from the drop down menu in the upper left, select Protocols:

enter image description here

The classes that implement the protocol will be in the list.

Edited to add info from Rob's comment:

Note that this only finds classes that, either in their public header or in their implementation declare that they conform to the protocol. If conformance to the protocol is declared somewhere else, those classes will not show up.

Say you have a protocol defined somewhere as

@protocol MyProtocol <NSObject>
…
@end

A class with a public header MyClass.h like this will show up:

@interface MyClass : NSObject <MyProtocol>

Also, a class that is extended in the .m file like this will show up

@interface MyObject () <SomeProtocol>
…
@end

@implementation MyObject 
…
@end

A class extension MyClass_Extension.h like this will not show up:

@interface MyObject (Extension) <SomeProtocol>
…
@end

Upvotes: 8

Related Questions