Search code examples
objective-ccocoa-touchprotocolsclass-extensions

Why would you want a class to conform to a protocol privately?


I've been looking at Apple's MVCNetworking example project and part of the interface definition for AppDelegate is puzzling me. In the .h file we have this:

@interface AppDelegate : NSObject
{
  ...

But in the .m file we have this:

@interface AppDelegate () <SetupViewControllerDelegate>
  ...

So this class is privately conforming to the protocol. But why would you want to do this instead of publicly declaring it in the header?


Solution

  • It looks like the implementation uses a SetupViewController internally in one of its "private" methods presentSetupViewControllerAnimated:. Since the view controller is not publicly accessible (through a property or otherwise), there's no need to declare the class as conforming to the protocol from the public point of view. In other words, the protocol is related only to the implementation of the class, and not to the public interface that it presents.