swift - 如何在 Xcode 中格式化代码,包括标记

标签 swift xcode formatting comments markup

我知道使用 Xcode 可以使用编辑器 -> 结构 -> 重新缩进来格式化代码,我遇到的问题是当我想重新缩进所有代码(包括标记)时这个:

/**
     Append new motive to motives array
     - parameters:
        - name: A brief description of motive.
     - returns: false if is empty otherwise true
*/

注意:如果我选择所有代码并重新识别它,标记代码将如下所示:

/**
     Append new motive to motives array
     - parameters:
     - name: A brief description of motive.
     - returns: false if is empty otherwise true
*/

这将影响显示的快速帮助,我在缩进之前和之后添加了两张图片。

缩进之前快速帮助:

Before Indent Quick Help

缩进后快速帮助:

enter image description here

看看在缩进我的代码后,快速帮助没有按应有的方式显示,特别是参数行它消失了,因为它需要从-参数缩进: 一个选项卡。

问题是如何缩进我的代码,包括对标记的适当缩进,或者如何选择我的所有代码缩进它但不影响标记。

最佳答案

看起来还有一些错误尚未修复。 我推荐下面的方式来描述参数。

基本(与 Apple Development 相同)

/**
 Append new motive to motives array

 - parameters name: A brief description of motive
 - parameters opt: A options

 - returns: false if is empty otherwise true
 */
public func exampleFunc(_ name: String, options opt: Options) {
  ...
}

但我更喜欢使用 XCode 的自动缩进。

自动缩进(推荐方式)

/**
Append new motive to motives array

- parameters name: A brief description of motive
- parameters opt: A options

- returns: false if is empty otherwise true
*/
public func exampleFunc(_ name: String, options opt: Options) {
  ...
}

即使使用自动缩进,它也会使格式始终相同。

关于swift - 如何在 Xcode 中格式化代码,包括标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42742343/

相关文章:

iOS UIWebView TextField - 输入文本后点击键盘上的“完成”按钮时应用程序崩溃

iphone - 如何显示电子邮件已发送通知 ipad

谷歌地图的 IOS 更改包标识符

windows - 为了可读性,我应该在 Notepad++ 中使用什么语言选项和我的 Windows 主机文件?

ios - 我的打印语句都没有出现在 Xcode 控制台中

IOS应用通过Linkedin认证SDK登录

ios - 如何使用 xcconfig 文件在不同平台的 XCFramework 中链接正确的框架

windows - 将换行格式从 Mac 转换为 Windows

python - 当逐行应用于 pandas DataFrame 中的 numpy.int 列时,整数格式规范 'd' 会产生 ValueError

json - 可选(<OS_dispatch_data : data[0x7f97b145f2f0] = { leaf, 大小 = 17290,buf = 0x11a63f000 }>)