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;
  • By "description" do you mean interface or implementation? You're showing one of each in your code. – Caleb Jul 17 '13 at 2:41
  • 2
    I believe by "description" he means "documentation". – Kitsune Jul 17 '13 at 2:42
  • I mean simple method descriptions ie, when holding "alt" and showing what the method does. – Oliver Dixon Jul 17 '13 at 2:42
  • Is this the sort of thing you're talking about? stackoverflow.com/questions/174315/… – Kitsune Jul 17 '13 at 2:46
  • 1
    Holding "alt" is an IDE feature, it has nothing to do with the Objective-C language. In the .h file you place (by convention) the "interface". It contains declarations of the externals of the class, such as the line following "//Within Header?" above. In the .m file, inside the "implementation", you place the definitions of the methods, such the definition you have above following "//Within Implementation?". The interface defines the externals of the class, and the implementation defines how it works internally. (This is similar to how C, C++, and a number of other languages do it.) – Hot Licks Jul 17 '13 at 2:46

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


/// 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:


| improve this answer | |
  • This is a fantastic find, I was hoping Apple would come to there senses and allow this feature. Definitely a +1 – Popeye Oct 18 '13 at 8:31
  • I can only see the description when Alt + click in declaration file. But if this method is called using an object from other class I can only see declared in foobar.h file. Did I do anything wrong ? – GoodSp33d Dec 18 '13 at 12:59
  • I don't exactly get what you mean or what you expect the behaviour to be, but all I'm pointing out is: Alt+click on a documented method name anywhere in Xcode, and you'll see documentation (also in Quick Help) regardless if the comments are in .h or .m. Please elaborate more if I missed your point. – Q8i Dec 18 '13 at 14:40
  • Awesome find, I'll definitely be using the /// more in the future. +1 – rebello95 Feb 22 '15 at 2:31
  • 2
    In Swift 2 comments can be written using markdown syntax (available in Xcode 7 in Fall 2015) and are parsed by Xcode when asking for code documentation as well as in playgrounds. See developer.apple.com/swift – zmit Jun 10 '15 at 11:46

What you are describing are called “documentation comments”, or “doc comments” for short.

Xcode, as of version 4.6.3, does not display your own doc comments in a pop-up window or its quick help inspector. You have to compile your comments into a “docset” to get Xcode to display them. There are tools to do that, but there is no way to get Xcode to reload a docset except by quitting and restarting it, so I don't recommend bothering.

Xcode 5 (which is currently available as a developer preview for paid members of the OS X and iOS developer programs) does display the doc comments for your own code; see “Quick Help” on the Developer Tools Features page. You must write the doc comments in the header file. You may use either doxygen or headerdoc format.

| improve this answer | |

In objective-c where do I place the description?

Objective-C compilers like gcc and llvm don't care how you document your code. There are several different documentation generators such as Doxygen and HeaderDoc that can build documentation from appropriately formatted comments, usually in your header files. Additionally, Xcode makes it easy to jump to the definition of symbols defined in your code, and it's "quick help" inspector can show you definitions, both without any special annotations in your code.

| improve this answer | |

Your Answer

