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

前端 未结 2 788
南方客
南方客 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];
    

提交回复
热议问题