是否有“覆盖/实现方法”的 Xcode 版本?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2222952/
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:06:57  来源:igfitidea点击:

Is there an Xcode version of "Override/Implement Method"?

objective-cxcode

提问by morgancodes

This is one of my favorite eclipse features. Does it exist in Xcode? I'm getting tired of cutting and pasting from my header files in to my implementations.

这是我最喜欢的日食功能之一。它存在于 Xcode 中吗?我厌倦了从我的头文件剪切和粘贴到我的实现中。

回答by nicktmro

Just type "dash" then "space" and start typing the method name that you want to override. Now push Esc. Example:

只需键入“破折号”,然后键入“空格”,然后开始键入要覆盖的方法名称。现在按 Esc。例子:

- tab

will prompt your to pick a method that overrides any of the TableViewDatasource / Delegate methods. Hit Return and it will automatically provide the return type too...

将提示您选择覆盖任何 TableViewDatasource / Delegate 方法的方法。点击返回,它也会自动提供返回类型......

Here's a pic of what it looks like and notice that I did not provide the return type myself: enter image description here

这是它的外观图片,请注意我自己没有提供返回类型: 在此处输入图片说明

Cheers...

干杯...

回答by TechZen

This is the kind of task that a user script is useful for. I use this one I banged out in ruby.

这是用户脚本非常有用的任务类型。我用这个我用红宝石敲出来的。

#! /usr/bin/env ruby -w


dash="------------------------------------"
r=/(^.+);/ # find entire function definition
pr=/(\w+(:|;))/ #find named parameters to make selector style string
s=STDIN.read
s.each_line() do |l|
  m=l.match(r)
  if m
    n=l.match(/:/) 
    if n  #if the function as one or more parameters
     params=l.scan(/(\w+:)/) 
     puts m.captures[0] + "{\n\n}//"+dash + params.to_s + dash +"\n\n"
    else #method has no parameters
      puts m.captures[0]+ "{\n\n}//"+dash + m.captures[0] + dash +"\n\n"
    end 
  end
end

To use, select a header method definition, run the script, switch to implementation and paste. This one adds in my preferred method comments boiler plate so you can customized that as you wish.

要使用,请选择标题方法定义,运行脚本,切换到实现并粘贴。这个添加了我的首选方法注释样板,因此您可以根据需要对其进行自定义。

回答by John Wang

Check out Accessorizer, it may not be exactly what you're looking for, but it could help in other things that you may like. I haven't used it extensively yet, but I got it as part of one of MobileOrchard's bundle.

查看Accessorizer,它可能不是您正在寻找的东西,但它可以帮助您处理其他您可能喜欢的事情。我还没有广泛使用它,但我把它作为MobileOrchard捆绑包的一部分。

回答by Rob Keniger

Take a look at the ODCompletionDictionaryplug-in for Xcode. It allows you to define expandable macros that are configurable with many options. It is an enormous time saver.

查看Xcode的ODCompletionDictionary插件。它允许您定义可使用许多选项配置的可扩展宏。这是一个巨大的节省时间。

回答by Vasiliy Kulakov

With Swift, pressing CTRL+SPACEin the class body will bring up auto-complete for methods. Just start typing the method name.

使用 Swift,在类主体中按CTRL+SPACE将调出方法的自动完成。只需开始键入方法名称。

If you're extending a class, XCode 10 doesn't seem to automatically insert overridewhen necessary.

如果您要扩展一个类,XCode 10 似乎不会override在必要时自动插入。