Drux
Drux

Reputation: 12660

Swift documentation comments for overriden methods?

I would like to add markup documentation to a Swift function that is implemented owing to the fact that a class conforms to UICollectionViewDataSource. For instance:

///
/// - returns: Why is this documentation ignored?
///
override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return 2
}

Apparently my comments are ignored and the generated documentation remains the one inherited from the contracts definition (or some other default location), for Quick Help (in Xcode 7.1.1) includes this text:

Returns The number of rows in section.

How can I "override" such a default documentation to call out changes in my implementation?

Upvotes: 2

Views: 1203

Answers (1)

sunshinejr
sunshinejr

Reputation: 4854

Seems like in overridden functions you need to give the multi-line comment (seems like /* */ doesn't work, you need /** */) instead of multi single-lines. What is interesting, multi single-line comments work fine for not overridden functions. What is even more interesting, as you are typing the method you get the correct, overridden comment, but Quick Help just ignores it once you type it off and click alt.

Example:

/**
    Works fine as you are typing.
*/
override func viewDidAppear() {
    print("test")
}

Upvotes: 1

Related Questions