How to create pop-up help for your own code in Xcode 5

Screen Shot 2014-05-03 at 11.17.05You know this super helpful feature that displays pop-up help windows in Xcode? The one I always forget is there? CMD-Hover over a method you’re calling and something like the above window is displayed. For Apple’s own code it even features links to the documentation.

We can do this in our own code as well using Doxygen style comments. Just above your own methods, add the following comment style block:

Now CMD-Hover over this method and that lovely box is displayed – it works anywhere you call it, even in different classes. This makes it a really useful feature, especially when you’ve forgotten how and why you’ve constructed code several moths down the line.

The parameters in those comments don’t need to be in order, Xcode will parse them no matter if @brief is at the top or @author is at the bottom. Empty lines don’t matter either, but they’re easier on the eyes.

The whole block is enclosed in standard /* multiline */ comments. The asterisks at the beginning of each line are not necessary either. Add one of the @ short codes on a new line, followed by your definitions. Some of the helpful ones are:

  • @brief – optional summary
  • @author – the author of the function, great for collaborative code (optional)
  • @param – input parameter (the first word right after is assumed to be the type)
  • @since – since which version this method is available (optional)
  • @code and @endcode – give a brief usage example that’s formatted as a code block (optional)
  • @see – adds a bold formatted “See Also” comment (optional)

I’m sure there are others, but I haven’t found any Apple documentation on those yet. Explore and document!

And check out Phil Beauvoir’s article for more tips on how to make this work for code completion:

This is one of those features that I wish Apple would tell you about. Perhaps in their… what’s it called.. documentation?

About Jay Versluis

Jay is a medical miracle known as Super Survivor. He runs two YouTube channels, five websites and several podcast feeds. To see what else he's up to, and to support him on his mission to make the world a better place, check out his Patreon Campaign.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.