Defeating the “multiple methods named 'xxx:' found” error

前端 未结 2 770
南方客
南方客 2020-12-09 08:03

In my current project inside the file ViewController.m, I am running the method:

[[connection writer] writeData: data];

It returns the war

相关标签:
2条回答
  • 2020-12-09 08:48

    Make sure [connection writer] is actually returning a TCPWriter*. If it is returning an id, then the compiler will not know which writeData to use. Also, make sure you are importing the TCPWriter.h file - if the compiler does not see the header files, it will default to returning id, which will get you back to the same problem.

    Try

    TCPWriter* writer = [connection writer];
    [writer writeData: data];
    

    or

    [(TCPWriter*)[connection writer] writeData: data];
    
    0 讨论(0)
  • 2020-12-09 08:53

    As an alternative to the splendid answer above, you can cast the object to the right type to get rid of the warning too, like so:

    [(NSView*)textView setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)]; // for horizontal scrolling
    
    0 讨论(0)
提交回复
热议问题