Xcode4自动生成注释

转载自:http://blog.csdn.net/cococoolwhj/article/details/7027506#t1


Xcode4方法:

要自动加上注释和生成文档, 注释也是有一些格式的:

变量结构体的注释方式为

[cpp]  view plain copy
  1. /** 
  2.   *The name of the model of car 
  3.  */  
  4. NSString *modelName;  

也可以这样:

[cpp]  view plain copy
  1. int i; /**<  An integer value  */  

注意 /**< 后面和 */ 前面有空格, 最好加上

方法的注释为:

[cpp]  view plain copy
  1. /** 
  2.  *  @brief  <#Description#> 
  3.  * 
  4.  *  @param  sender  <#sender description#> 
  5.  */  
  6. -(void)searchButtonAction:(id)sender;  

这些格式如果一个一个手动敲上去那也太麻烦了, 得不偿失, 这里有写好的脚本可以直接用, 设置好了一个快捷键就行!

Xcode4和3变化很大, HeaderDoc好像没有了, 至少我目前没找到, User Scripts也不支持了

不过还是有2种方法可用, 第一种, 下载下面这个老外自己写的一个workflow, 配置到xcode, 设置快捷键既可以用

first download the service.

Next, unpack the file and copy it to your ~/Library/Services directory. The name of the service is “Document Code” though you can rename it to anything you’d like. This is the name that will appear in the Services menu.

Once you have the service installed, you need to open System Preferences. Select the “Keyboard” preference pane, and select the “Applications Shortcuts” configuration in the “Keyboard Shortcuts” tab.

Xcode4自动生成注释_第1张图片

Click the + button to add a shortcut for our new service.

Xcode4自动生成注释_第2张图片

然后在xcode里面选中需要注释的代码, 直接利用你刚刚设置的快捷键就会自动加上注释!


第二种方法是利用一个mac工具原封不动的把在xcode3里面运行得好好的rb脚本配置到系统的服务里面, 设置一个快捷键也可以, 上面那位仁兄写的那个workflow效率一般, 我试过了, 用起来很卡, 还是原来的好, 建议用这个方法! (http://www.brokenrul.es/blog/?p=761#.TtXrJL92Re4)

Since I couldn’t find a good solution for creating a keyboard shortcut to create a doxygen snippet based on your selection in XCode4 I have to write a short and untypical technical blog post about how to get that.
We’re trying to document our code as good as possible. While well written code is self-explainatory, interfaces and functions in header files simply have to be documented correctly. To do so, we useDoxygen, here in the Broken Rules engine room. We’ve had a pretty good XCode integration for generating Doxygen snippets on the press of a button but XCode4 broke the scripting support. In order to get our comfortable scripts back I had to look at a nearly forgotten part of the OSX operating system: Services.

You need the following two things in order to install the Ruby-based doxygen generator script that I’m using:

  • Waffle Software’s ThisServices, a tool to quickly hook up your own scripted services in OSX’s “Services” menu.
  • Doxygen.rb based on Fred McCann’s doxygen script.

Then simply execute the following two steps in order to install the script and make it start on the press of a key.

First, start ThisService and create a new “Filter”-type service based on the above Ruby script. Simply select Ruby file and give it a name. Then select “Filter” as the type of service and leave the rest of the controls untouched. Your settings should look like this:

Xcode4自动生成注释_第3张图片Press “Create Service” to create the service. Once that is done you can proceed to step two.

Next, open “System Preferences” and go to “Keyboard” > “Keyboard Shortcuts”. Select “Services” in the left pane. Browse for the name you gave your new service. It’s hidden somewhere in the huge list of services. Once you’ve found it you have to assign a keyboard shortcut and tick its checkbox, otherwise it will not show up in your “Services” menu:

Xcode4自动生成注释_第4张图片

Once you’ve set the shortcut, you’re done. Simply select any text in XCode and press your keyboard shortcut. The script will try its best at understanding your code but you might have to extend it in order to suite your coding habits. Have fun!

你可能感兴趣的:(Xcode4自动生成注释)