在 iOS 中是否有任何最简单的方法来实现所有必需的协议方法?

Is there any easiest way to implement all required methods of protocol in iOS?

首先,它不是 this question 的副本,因为我在 Xcode 中找不到任何关于离线文档、合适的答案和未来发布更新的讨论。

实际上我来自 android 和 java 背景,目前也开始开发 iOS 应用程序。众所周知,在 IDE 中给出的建议的帮助下,我们可以通过按 Alt + Enter 轻松实现 Interface 的所有方法。

而在iOS这里我们每次都要看引用,搜索所有必需的和可选的方法,然后一个一个手动实现,耗费时间暂时还好但是

我的问题是:

  1. 是否有任何最简单的方法来在文档中首次查找时查看所有必需的方法或在 IDE 的帮助下实现所有必需的协议方法?
  2. 我们是否有可能在 Xcode 的更新版本中获得此功能?
  3. 我不能保证一直能上网,那我怎么才能看到当时的文档呢?

前往 Xcode -> preferences(在 top-left 角落) -> downloads -> 此处您将看到可以下载的项目列表。下载 documentation for iOS x.x 版本。所以现在,只要你离线..你可以去 help(window 中的顶部栏)-> documentation 并搜索整个 ios 文档..所有的开发指南等

请继续声明您的 class 采用了相关协议。

Xcode 如果您未能实现任何必需的方法,将指出错误:

从显示三角形下的列表(带有灰色“!”图标的项目),您可以得到缺失方法名称的提示。您可以开始输入,自动完成将完成剩下的工作。


Xcode9 的更新:

现在看来,你可以一键auto-fill方法:

Refactoring

  • Rename a symbol in a single file or in a project across Swift, C, Objective-C, C++ files, and Interface Builder files.
  • View all the possible changes in one editor pane.
  • Convert method signatures between Swift and Objective-C formats.
  • Update properties, getters, setters, and synthesized iVars as needed.
  • Apply a fix-it everywhere with one button.
  • Automatically fill in missing cases in switch statements, and mandatory methods for protocol conformance with one click.
  • Extract method functionality for all supported languages, along with other language-specific local refactoring.

(强调我的)

确实:

单击 "Fix" 添加必要的方法存根。