14

How can I show a brief description of a function while typing like the image show below? I've tried many different options all have failed.

enter image description here

Option + click works but that's not what I'm looking for.

Option 1

 /// Testing...
  /// - returns: false
  func testing()->Bool{
    return false
  }

Option 2

/**
Testing option two
*/
func testing()->Bool{
        return false
}

This issue has been fixed in Xcode 9

kye
  • 2,166
  • 3
  • 27
  • 41

4 Answers4

18

If you are looking for the way to document self-created method in swift then this might give you a way out.

import Foundation
///  A two-wheeled, human-powered mode of transportation.
class Bicycle {
/**
    Frame and construction style.

    - Road: For streets or trails.
    - Touring: For long journeys.
    - Cruiser: For casual trips around town.
    - Hybrid: For general-purpose transportation.
*/
enum Style {
    case Road, Touring, Cruiser, Hybrid
}

/**
    Mechanism for converting pedal power into motion.

    - Fixed: A single, fixed gear.
    - Freewheel: A variable-speed, disengageable gear.
*/
enum Gearing {
    case Fixed
    case Freewheel(speeds: Int)
}

/**
    Hardware used for steering.

    - Riser: A casual handlebar.
    - Café: An upright handlebar.
    - Drop: A classic handlebar.
    - Bullhorn: A powerful handlebar.
*/
enum Handlebar {
    case Riser, Café, Drop, Bullhorn
}

/// The style of the bicycle.
let style: Style

/// The gearing of the bicycle.
let gearing: Gearing

/// The handlebar of the bicycle.
let handlebar: Handlebar

/// The size of the frame, in centimeters.
let frameSize: Int

/// The number of trips travelled by the bicycle.
private(set) var numberOfTrips: Int

/// The total distance travelled by the bicycle, in meters.
private(set) var distanceTravelled: Double

/**
    Initializes a new bicycle with the provided parts and specifications.

    - Parameters:
        - style: The style of the bicycle
        - gearing: The gearing of the bicycle
        - handlebar: The handlebar of the bicycle
        - frameSize: The frame size of the bicycle, in centimeters

    - Returns: A beautiful, brand-new bicycle, custom built
      just for you.
*/
init(style: Style, gearing: Gearing, handlebar: Handlebar, frameSize centimeters: Int) {
    self.style = style
    self.gearing = gearing
    self.handlebar = handlebar
    self.frameSize = centimeters

    self.numberOfTrips = 0
    self.distanceTravelled = 0
}

/**
    Take a bike out for a spin.

    - Parameter meters: The distance to travel in meters.
*/
func travel(distance meters: Double) {
    if meters > 0 {
        distanceTravelled += meters
        ++numberOfTrips
    }
}
}

enter image description here

Swift-Documentation on NSHipster

Aman Gupta
  • 985
  • 1
  • 8
  • 18
11

I am using Xcode 9.4.1 and I found this...

enter image description here

Parameters picked from function automatically. Place your cursor on the line above the function.

/// <#Description#>
///
/// - Parameters:
///   - param1: <#param1 description#>
///   - param2: <#param2 description#>
Farhan Arshad
  • 375
  • 3
  • 9
9

Select your function or place the cursor before your function, then click

Xcode - Editor - Structure -> Add Documentation.

/**
 <#Description#>
 */

Save the file, or simply restart the Xcode. Then check the suggestion while calling the respective function. I hope this might help.

Mithun kumar
  • 662
  • 3
  • 7
2

Have you set:

Preferences -> Text Editing -> Suggest completions while typing

It might also help to install the guides and sample code at:

Preferences -> Components -> Documentation Tab -> "Check and Install Now" or the arrow next to guides and sample code to just download it once