How many times have you been looking at Swift or Objective-C code in Xcode and can’t remember what a framework method, argument, constant, etc. means? Did you know that help — full documentation — is just a keystroke away? Did you also know that you can add the same type of pop-up, context-sensitive help to your own code? Here’s how. Let’s say you’re looking at the following NSString class method and can’t remember exactly what the call does, what parameters it takes, and what is its return value:
NSString *result = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:&error];
Highlight the method name, parameter, even the enum, and then press the following key combination on your keyboard:
[command] + [control] + [shift] + [?]
or, using key symbols:
⌘ ⌃ ⇧ ?
Here’s what you’ll see: a context-sensitive help/documentation popup. Note that I added the red lines to highlight content. The red highlighting is not what Xcode provides (click to enlarge):
So you immediately get information about the method, parameter, enum, even constant’s:
- Declaration (formal language signature);
- Description (textual explanation of the entity’s purpose);
- Parameters (a full list of names and definitions);
- Returns (the value returned by a method/function, if applicable);
- Availability (what version of iOS that the entity became available in — and sometimes in what version it was deprecated);
- Declared In (the framework which contains the entity); and,
- More (generally, the formal definition of the entity with explanations and other links).
Check out what I get if I click on the “More Type Method Reference” link as shown in Figure 1 (click to enlarge):