Re: Compiler error - method not found on object which conforms to protocol

Sandor Szatmari


Thanks for your input.

On Mar 30, 2021, at 10:13, Alex Zavatone via <zav@...> wrote:

Hi.  I’m late to the discussion, but have you put the property or method on the class?
Yes, the conforming class did have the method/property implemented.  

When you have a class that conforms to a protocol, my understanding is that you cross your heart and swear to die that you will make sure that the class doing the conforming will implement those methods/properties.  
Yes the compiler warns if the conforming class does not fully implement the protocol.  And of course there are required and optional aspects to a protocol. The compiler only warns about required elements that are missing.

I’m not sure if this would work with inherited methods or properties as I’ve never tried it.

Now, if a method missing for a property (if it is implemented), I’d expect it would be accessor methods.  If your conforming class has the property declared, try creating the set and bet methods.  If the property isn’t declared, try declaring it and I’d expect Objectice-C to auto declare the accessors.  If it doesn’t, then add them to see if the error goes away.

I had all the pieces in place except for the import to inform the compiler of the methods declared in the protocol.  The forward declaration in the header slightly masked the issue so that I didn’t recognize why the error was being generated. 

The object was already declared as conformant

@property (readonly) id<DataSrcProto> dataSource;

But, without the actual import in the scope of the compilation unit, the compiler had no idea what methods were actually declared in the protocol.


Best of luck,
Alex Zavatone

On Mar 27, 2021, at 8:54 AM, Sandor Szatmari <> wrote:

Thanks Sak,

On Mar 27, 2021, at 04:54, Sak Wathanasin <sw@...> wrote:

On 27 Mar 2021, at 01:41, Sandor Szatmari <> wrote:
@protocol dataSrcProto

serverPort isn't a property, so you have to use

This is how I’m working around the error right now.  Like this I get a compiler warning, method not found, return type defaults to id.  
[self.dataSource serverPort];

Port = (NSUInteger)[self.dataSource serverPort];

This succeeds at runtime, but of course smells, and doesn’t squelch the warning.

If you want it to be a property, make it so

I tried implementing serverPort as a property and I still get the same error


@protocol dataSrcProto
@property (readonly) NSUinteger serverPort;


Join to automatically receive all group messages.