Xcode 6中的文档方法和枚举

Nul*_*sis 4 ios swift xcode6 ios8

我在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
 }
Run Code Online (Sandbox Code Playgroud)

而且我希望这个记录类似于intellisense在C#中的工作方式,在我输入的那一刻DateFormat.ShortDateFormat,弹出窗口会告诉我这会产生7/28/2014.

我还想用我写的那些难以记忆的函数来做这件事,这些函数返回特定的东西以使我更容易,所以我不必回到文件并查看它究竟做了什么(不是我有这些功能很多,请注意)!

我怎么能做这样的事情?

Mil*_*ilo 5

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;
Run Code Online (Sandbox Code Playgroud)

alt-click foo:的结果就是这个

此搜索

在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 {...}
Run Code Online (Sandbox Code Playgroud)

如上所述进行alt单击时,这会给出相同的示例.

对于枚举,其原理与上述原理相同,/** */但也///用于单独的枚举描述.

/**
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
}
Run Code Online (Sandbox Code Playgroud)

结果是一个整齐的格式,项目符号列表: 图像2

当alt-单击其中一个实际案例时: 图片3.

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


Nul*_*sis 1

为此,您只需添加三个正斜杠 (///) 即可完成此操作。

/// 我的评论出现在“Intellisense”弹出窗口中