未找到方法定义... Xcode 自动存根?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2370209/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 19:09:54  来源:igfitidea点击:

Method Definition Not Found... automatic stub with Xcode?

objective-cxcodecode-completion

提问by Dan Rosenstark

I don't want to give up before asking, because this is basic functionality in any Java/.Net IDE. The compiler tells me:

在询问之前我不想放弃,因为这是任何 Java/.Net IDE 中的基本功能。编译器告诉我:

Incomplete implementation of class...
Method definition for '-someMethod:' not found

but clicking, right-clicking, praying and Google searching have not gotten me to automatically create a method stub from this. Can Xcode create a method stub for me and take me there?

但是点击、右键点击、祈祷和谷歌搜索并没有让我自动创建一个方法存根。Xcode 可以为我创建一个方法存根并将我带到那里吗?

If not, why might that be (aside from "real programmers enjoy typing")?

如果不是,为什么会这样(除了“真正的程序员喜欢打字”)?

Edit:I thought that option-escapebasically solved this for me, but it does not. It doesn't seem to be aware of all (any?) of the interfaces my class implements.

编辑:我认为这option-escape基本上为我解决了这个问题,但事实并非如此。它似乎不知道我的类实现的所有(任何?)接口。

采纳答案by Dan Rosenstark

What the OP (me) is talking about is in Java, where the interface is implicit. However, the case that is the same in Xcode is one where there is NO method yet defined in any interface.

OP(我)正在谈论的是 Java 中的接口,其中接口是隐式的。然而,Xcode 中同样的情况是在任何接口中都没有定义任何方法。

AppCode handles this case, Xcode does not (unless somebody answers this question, but it's been here for a while):

AppCode 处理这种情况,Xcode 不处理(除非有人回答这个问题,但它已经存在一段时间了):

AppCode popover showing method creation

AppCode 弹出窗口显示方法创建

Later:People have answered the question, but Xcode still doesn't do this.

后来:人们已经回答了这个问题,但 Xcode 仍然没有这样做。

回答by Steven Noyes

This might be an option to file a feature request to Apple. Typically, I will design my @interface file and then do a copy/paste of the @interface to the @implementation keeping typing to an absolute minimum.

这可能是向 Apple 提交功能请求的一个选项。通常,我会设计我的 @interface 文件,然后将 @interface 复制/粘贴到 @implementation 中,保持输入绝对最少。

However, it would be nice to be able to click on the warning and have Xcode simply create the method at the botto of the @implementation.

但是,如果能够单击警告并让 Xcode 简单地在 @implementation 的底部创建方法,那就太好了。

NOTE: it is valid to keep the semicolon after the @implementation

注意:在@implementation 后保留分号是有效的

@interface PCStackValue : NSObject <NSCoding, NSCopying>
{
}

- (id) initWithDisplayRadix:(int) newRadix;

@end

@implementation PCStackValue

- (id) initWithDisplayRadix:(int) newRadix;
{
   … do something;
}
@end    

回答by emp

I don't mind this behaviour. For one, the implementation does not necessarily exist as it might be dynamic. I also categorize my code using #pragma mark - MyCategoryand want the implementations in specific locations in the source file.

我不介意这种行为。一方面,实现不一定存在,因为它可能是动态的。我还使用#pragma mark - MyCategory对我的代码进行分类,并希望在源文件中的特定位置实现。

However, I agree - I don't want to type the stub itself.

但是,我同意 - 我不想输入存根本身。

You can do it per method.
Go to your implementation file and start typing - prefixand hit ESC and you should see valid completions matching the prefix. You must start with typing a - or + for this to work, for instance methods and class methods respectively.

您可以按方法执行此操作。
转到您的实现文件并开始输入- 前缀并按 ESC,您应该会看到与前缀匹配的有效补全。您必须首先键入 - 或 + 才能使其工作,例如分别是实例方法和类方法。

Sometimes you don't know what it is you are to implement! Open the Issue Navigator, and click the disclosure rectangle. There should be a line that says Method declared here. Click on it to see the method that lacks implementation.

有时您不知道要实施的是什么!打开问题导航器,然后单击显示矩形。应该有一行写着Method 在此处声明。单击它可以查看缺少实现的方法。

回答by Abhi Beckert

What you're looking for doesn't exist. I just use auto-complete (it usually works for me) or copy/paste.

你要找的东西不存在。我只是使用自动完成(它通常对我有用)或复制/粘贴。

What makes you think Xcode would have a feature just because eclipse has it? Eclipse is ~10 years old, while Xcode is ~23 years old. Any features copied would most likely be in the other direction.

是什么让您认为 Xcode 会因为 Eclipse 拥有它而拥有它?Eclipse 大约有 10 年的历史,而 Xcode 大约有 23 年的历史。复制的任何特征很可能在另一个方向。

It would make a great feature request however. Perhaps opening the auto-complete menu on an empty line inside @implementation .. @endcould give a list of not-yet-implemented methods.

然而,它会提出一个很好的功能请求。也许在内部的空行上打开自动完成菜单@implementation .. @end可以提供尚未实现的方法列表。

But I'm not sure how well it would work in practice, because of NSObjectcategories. There might literally be thousandsof "not-yet-implemented" methods in the auto-complete menu. But it could at least show some of the most likely ones.

但由于NSObject类别的原因,我不确定它在实践中的效果如何。自动完成菜单中可能有数以千计的“尚未实现”的方法。但它至少可以显示一些最有可能的。

It seems like this compile error/warning would also be a good candidate for the new "Fix It" feature.

看起来这个编译错误/警告也是新的“修复它”功能的一个很好的候选者。

Also: learn to type faster :p

另外:学习打字更快:p