Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-C method description (doc comments)

Tags:

I'm currently learning Objective-C and need to know how to write a method description. I'm having a lot of difficulty learning how to do this in Objective-C.

In Jave we have this

/** < h2 >MethodName</ h2 > < p >Various Description, can use html with images etc.</ p > */ private void methodName(args[]..) {  }  

In objective-c where do I place the description? Also does this to be in the header file or the implementation file?

//Within Implementation? - (float)gteHeightPercentage:(float)percentageToGet {     return self.view.bounds.size.height * percentageToGet; }  //Within Header? - (float)getWidthPercentage:(float)percentageToGet; 
like image 758
Oliver Dixon Avatar asked Jul 17 '13 02:07

Oliver Dixon


People also ask

How do you comment in Objective-C?

Comments in Objective-C enable the developer to add notes about the code or comment out sections of code that should not be compiled. Comments can be single line comments (using the // marker) or multi-line (beginning with /* and ending with */). Commenting is considered to be good practice.

Can I use C in Objective-C?

You really can't use C in Objective-C, since Objective-C is C. The term is usually applied when you write code that uses C structures and calls C functions directly, instead of using Objective-C objects and messages.


1 Answers

Update: The format below works for Objc. If you want to document swift code, refer to NSHipster's blog about Swift Documentation

The Xcode 5 can do what you want. Thanks to Wonil Kim, in the .h file:

/**   * Add new message between source to destination timeline as empty name string  * @author Wonil Kim  *  * @param sourceId Source timeline entity ID  * @param destId Destination timeline entity ID  * @return A newly created message instance  */ - (ISMessage*)messageFromTimeline:(NSInteger)sourceId toTimeline:(NSInteger)destId; 

Once this is done, you can alt+click on the method name, and.. voilà!

Of course, as you can see on Kim's blog, this is not the only way:

/*! Some description of the method....  * \returns  The result  */ 

Alternatively,

/// Some description to show up, done by: /// @author  Olly Dixon 

You got the point...

As many already have mentioned, Objective-C does not show you your documentation; in fact, neither does java (javadoc, may be). It's your IDE, in this case, the un-crashable Xcode :)

UPDATE2: Complete list of "Special Commands" in comments.

UPDATE3: Use VVDocumenter-Xcode if you'd like to enable auto-generation of documentation by ///.

UPDATE4:: VVDocumenter has be integrated in to Xcode:

Use the shortcut (⌥ Option + ⌘ Command + /) to add a documentation comment to your code if you are using Xcode 8 or above

like image 157
Q8i Avatar answered Oct 09 '22 05:10

Q8i