How to Add Auto-Complete Comment in Xcode (Swift)

Auto generate method comment in Xcode

You can use the Code Snippets library for this. It won't automatically generate placeholders for each parameter, but it's pretty useful nonetheless. Here's what you do:

  1. Write out a sample comment block in your code somewhere.
  2. Insert <#xyz#> where you want a placeholder named 'xyz' to appear. (These are like parameter completion placeholders, so you can tab between them and overwrite them.)

For example:

/**
* Method name: <#name#>
* Description: <#description#>
* Parameters: <#parameters#>
*/
  1. Open up the right hand sidebar. In the bottom pane click on the two curly braces icon to bring up the snippets library.
  2. Select and drag your text to the code snippets library.
  3. It'll create a new one. Double click on it, click edit in the popup, and give it a completion shortcut (e.g. comblk for comment block.)

Now, when you type 'comblk' anywhere in your editors, the autocomplete popup appears and you can hit return to paste in the snippet. The first placeholder will be selected and you can start typing the method's name. Hit tab to switch to description, and so on.

Not ideal but it's better than nothing. Snippets are a nice idea that Apple haven't quite finished implementing yet.

How can I make auto-complete display a list in Xcode

Press the escape key when auto-complete makes the first suggestion. This will display the list.

Swift method documentation - not showing in autocomplete

The reason is that Xcode parse the documentation displayed in the popover from a separate doc-set and not from the class files themselves.

Have a look here: https://stackoverflow.com/a/43982094/1415898
for a more complete answer.

Xcode 9 Autocomplete Not Working 100% - Partially Working

Deleting the DERIVED DATA folder seemed to fix my issue. Thanks to this post: swift println() not showing autocomplete options while writting code

Xcode code completion custom descriptions

I think the reason might be that there is no space after ///.

Right way should be

/// This is a description

As a matter of fact, if you add documentation for a function as mentioned in screenshot, comments are itself added wherein you can see that space is there after ///. Which is intact the right way to add comments/documentation.

Once you option click on the function calling, description is displayed.

The way Apple displays the description in autocomplete is something it does by itself. You may want to use AppleDoc for this.

Sample Image

In Xcode 7, Swift can't autocomplete Objective-C code

I think I figured this one out:

Our project has multiple targets, and most of the files belong to multiple targets. If you want autocompletion, the header you are importing has to be imported in the bridging header for every target the file belongs to.

When I imported the header I wanted in each bridging header, autocompletion started working as expected.

Update: Seems like you can consolidate down to one bridging header if that setup works for your project. That would prevent you having to update multiple headers every time you wanted to add an import.



Related Topics



Leave a reply



Submit