Objective-C: Protocol method implemented in class is not recognised by category conforming to protocol

Hi all,

Sorry for the mouthful of a subject line, but I wanted it to be
descriptive. :slight_smile: I have the following code:

  #import <Foundation/Foundation.h>
  
  @interface Test : NSObject
  - (id)testMethod;
  @end
  
  @implementation Test
  
  - (id)testMethod;
  {
    return nil;
  }
  
  @end
  
  @protocol TestProtocol <NSObject>
  - (id)testMethod;
  - (id)secondMethod;
  @end
  
  @interface Test (TestCategory) <TestProtocol>
  @end
  
  @implementation Test (TestCategory)
  
  - (id)secondMethod;
  {
    return nil;
  }
  
  @end

It generates the following warnings:

  $ clang test.m
  test.m:24:17: warning: incomplete implementation [-Wincomplete-implementation]
  @implementation Test (TestCategory)
          ^
  test.m:24:17: warning: method in protocol not implemented [-Wprotocol]
  test.m:17:1: note: method declared here
  - (id)testMethod;
  ^
  test.m:21:12: note: required for direct or indirect protocol 'TestProtocol'
  @interface Test (TestCategory) <TestProtocol>
         ^
  2 warnings generated
  
As you can see, the method declared in the protocol is defined in the
original class implementation and not the category that declares its
conformance to the protocol. I can't re-define the method in the
category and call through to "super" as that would go through to
NSObject.

My question is this: is this (a) a bug in clang, (b) a bug in my
understanding or (c) a combination of the above?

Hi all,

Sorry for the mouthful of a subject line, but I wanted it to be
descriptive. :slight_smile: I have the following code:

  #import <Foundation/Foundation.h>
  
  @interface Test : NSObject
  - (id)testMethod;
  @end
  
  @implementation Test
  
  - (id)testMethod;
  {
    return nil;
  }
  
  @end
  
  @protocol TestProtocol <NSObject>
  - (id)testMethod;
  - (id)secondMethod;
  @end
  
  @interface Test (TestCategory) <TestProtocol>
  @end
  
  @implementation Test (TestCategory)
  
  - (id)secondMethod;
  {
    return nil;
  }
  
  @end

It generates the following warnings:

  $ clang test.m
  test.m:24:17: warning: incomplete implementation [-Wincomplete-implementation]
  @implementation Test (TestCategory)
          ^
  test.m:24:17: warning: method in protocol not implemented [-Wprotocol]
  test.m:17:1: note: method declared here
  - (id)testMethod;
  ^
  test.m:21:12: note: required for direct or indirect protocol 'TestProtocol'
  @interface Test (TestCategory) <TestProtocol>
         ^
  2 warnings generated
  
As you can see, the method declared in the protocol is defined in the
original class implementation and not the category that declares its
conformance to the protocol. I can't re-define the method in the
category and call through to "super" as that would go through to
NSObject.

My question is this: is this (a) a bug in clang, (b) a bug in my
understanding or (c) a combination of the above?

(d) bug has already been fixed in TOT.

- fariborz

Well don't I look silly!

Thank you very much for your quick answer to my dumb question. :slight_smile: