目标C-“方法的重复声明";编译错误 [英] Objective C - "Duplicate declaration of method" compilation error

查看:88
本文介绍了目标C-“方法的重复声明";编译错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这段代码:

- (id) getSearchSuggestions:(NSString*)q;
- (NSOperationQueue*) getSearchSuggestions:(NSString*)q callback:(id<UserDelegate>)callback;
- (id) getSearchSuggestions;
- (NSOperationQueue*) getSearchSuggestions:(id<UserDelegate>)callback;

并且我Xcode在最后行上不断向我显示错误:

And I Xcode keeps showing me an error on the last line:

Duplicate declaration of method "getSearchSuggestions"

为什么?在我看来,签名都是不同的.

Why? It seems to me that the signatures are all different.

推荐答案

此签名:

- (id) getSearchSuggestions:(NSString*)q;

与该签名相同:

- (NSOperationQueue*) getSearchSuggestions:(id<UserDelegate>)callback;

所有对象指针均为id.因此,这两种方法都需要一个对象并返回一个对象.

All object pointers are id. So both of these are methods that take an object and return an object.

更好的名字的例子是:

- (id)searchSuggestionsForQueryString:(NSString*)q; // Or ForTag, or whatever "q" is
- (NSOperationQueue*)searchOperationQueueForQuery:(NSString*)q callback:(id<UserDelegate>)callback;
- (id)fetchSearchSuggestions;
- (NSOperationQueue*)searchOperationQueueWithCallback:(id<UserDelegate>)callback;

尚不清楚为什么要在此处返回操作队列,但这是用于执行此操作的方法的名称.

It's not exactly clear why you return an operation queue here, but this is the kind of name you'd use for a method that did that.

这篇关于目标C-“方法的重复声明";编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆