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


Alex Zavatone
 

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

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.  

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.

Best of luck,
Alex Zavatone

On Mar 27, 2021, at 8:54 AM, Sandor Szatmari <admin.szatmari.net@...> wrote:

Thanks Sak,

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

On 27 Mar 2021, at 01:41, Sandor Szatmari <admin.szatmari.net@...> wrote:
@protocol dataSrcProto
-(NSUinteger)serverPort;
@end

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

Thanks,
Sandor


@protocol dataSrcProto
@property (readonly) NSUinteger serverPort;
@end

Regards
Sak

Join cocoa@apple-dev.groups.io to automatically receive all group messages.