Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift method documentation - not showing in autocomplete

I am documenting my Swift methods as follows:

/// Extracts the server time from the API call response.
/// - parameter response: The HTTPURLResponse from which to extract the date.
/// - returns: The 'Date' header from the response, as a `Date` object.
/// - throws: If the 'Date' header is not found, or cannot be parsed to a `Date` object.
static func extractServerTimeFromResponse(_ response: HTTPURLResponse) throws -> Date {
    guard let serverTimeString = response.allHeaderFields["Date"] as? String else {
        throw RGOTimeSyncHelperError.invalidServerResponse
    }
    let formatter = DateFormatter()
    formatter.dateFormat = "EEE, dd MMM yyyy HH:mm:ss zzz"
    guard let serverTime = formatter.date(from: serverTimeString) else {
        throw RGOTimeSyncHelperError.dateParsingError
    }
    return serverTime
}

/// Calculates the offset of the local time compared to the server time.
/// - parameter serverTime: The time from the server.
/// - returns: The amount of seconds that need to be added to the client time, to match the server time.
static func calculateOffset(serverTime: Date) -> Int {
    let localTime = Date()
    let offset = Calendar.current.dateComponents([.second], from: localTime, to: serverTime).second!
    return offset
}

/// Add an offset in seconds to a given date.
/// - parameter date: The date to which to offset should be applied.
/// - parameter bySeconds: The offset, in seconds, that will be applied to the given date.
/// - returns: A new `Date` object, comprised of the given date, with the given offset applied.
static func offset(date: Date, bySeconds offset: Int) -> Date {
    let offsetDate = Calendar.current.date(byAdding: .second, value: offset, to: date)!
    return offsetDate

}

When I alt-click on the method signature anywhere, Xcode shows the quickhelp panel with the information that I have entered shown correctly.

Help Panel

However, when I start typing the method signature and autocomplete pops up, it does not show this information at the bottom of the autocomplete box as it does for Apple's APIs.

Autocomplete

Where in my comment syntax am I going wrong?

like image 814
Jacob King Avatar asked Oct 30 '22 10:10

Jacob King


1 Answers

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.

like image 144
Thomas Avatar answered Nov 15 '22 07:11

Thomas