ios - Xcode 6 中的文档方法和枚举

标签 ios swift ios8 xcode6

<分区>

我在 Swift 中有一个枚举:

 enum DateFormat{
   case ShortDateFormat //7/28/2014 ShortStyle
   case LongDateFormat  //July 28, 2014 LongStyle
   case LongFormatWithDay //Monday, July 28, 2014 FullStyle
   case CurrentDayThreeLetters //Mon
 }

而且我希望将其记录为类似于 C# 中智能感知的工作方式,在我键入 DateFormat.ShortDateFormat 的那一刻,弹出窗口将告诉我这会产生 7/28/2014。

我还想使用我编写的难以记住的函数来执行此操作,这些函数返回特定的内容以使我更容易,这样我就不必返回文件并确切地查找它做了什么(请注意,并不是说我有很多这些功能)!

我怎么能做这样的事?

最佳答案

HeaderDoc 标签适用于 Objective-C 和 Swift,尽管在 Swift 中,格式略有不同。在 Objective - C 中,记录方法的正确格式是这样的:

/*!
 * @discussion This is an example discussion.
 * @param bar - This is an example of a parameter.
 * @return An example for a return type
 */
-(id)foo:(bar)foobar;

alt-click foo: 的结果是这样的

image1

在 swift 中,文档的方式有点不同:

/**
This is an example discussion

:param: bar This is an example parameter.

:returns: This is an example return type.
*/

func foo(foobar: AnyObject) -> AnyObject {...}

这给出了与上面的 alt-clicking 相同的例子。

对于枚举,其原理与上面使用/** */ 格式的相同,但也使用/// 来描述单个枚举。

/**
Example enum description

- First: First example
- Second: Second example
- Third: Third example
- Fourth: Fourth example
*/
enum Example {
    ///First example
    case First
    ///Second example
    case Second
    ///Third example
    case Third
    ///Fourth example
    case Fourth
}

结果是一个格式整齐的项目符号列表:image2

当按住 alt 并单击其中一个实际案例时:image 3 .

您将使用自动完成功能获得所需的效果,如下所示: image4

关于ios - Xcode 6 中的文档方法和枚举,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25006366/

相关文章:

Swift 字典在不访问或不知道 key 的情况下获取值

ios - 调整ScrollView与多个SubView

ios - 如何取消特定 View 的通知中心视觉效果 (iOS)?

javascript - 通过 jQuery 更改 iOS 的输入占位符样式属性

ios - Xcode-7 : No such file or directory

ios - 使对象/图像在 Xcode 中随机出现和消失

xcode - 自动布局约束在 iOS 8 中有效,在 iOS 9 中失效

ios - 我如何知道应用内购买是否可以在我的应用中使用?

swift - 使用 Swift 在 Xcode 中填充 TableView

ios - 使用 Swift 和 Xcode 6 子类化 UIGestureRecognizer - 如何导入 UIGestureRecognizerSubclass.h?