Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
450 views
in Technique[技术] by (71.8m points)

objective c - Defeating the "multiple methods named 'xxx:' found" error

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

[[connection writer] writeData: data];

It returns the warning:

warning: multiple methods named 'writeData:' found

I am attempting to call the method:

- (void) writeData: (NSData*)data

...in TCPWriter.m. Unfortunately, there are two other writeData methods

- (void)writeData:(NSData *)data;

...in NSFileHandle.h and...

- (BOOL)writeData:(NSData *)data

...in NSURLHandle.h. This is especially confusing to me because [conn writer] should return the TCPWriter class and that class should call the correct writeData method. Furthermore, I am not even completely sure that NSFileHandle.h and NSURLHandle.h are even included in any of the libraries included in ViewController.h, rather than in a different part of the project.

How can I show the compiler which writeData method I want to call and why does this error happen?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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];

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...