Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I properly document a method with a completion handler in iOS swift

I'm documenting the code for my company's iOS application, and now I've moved on to methods that have a completion handler. Is there a specific method for documenting completion handlers, or should I just put it as part of the parameters?

for example:

/**
Description
- Parameters:
     - parameter1: description
     - parameter2: description
     - completion: description
*/

Is this the right way or is there another better way? Or maybe it should be in the "Returns" part of the documentation?

Thanks

like image 820
DatForis Avatar asked Nov 29 '22 14:11

DatForis


1 Answers

Since the previous accepted answer failed to compile under Swift 3 (Function types cannot have argument label.) I would like to add an updated answer:

/**
Find User ID from Request
- Parameter from: The request containing relevant information.
- Parameter completionHandler: The callback called after retrieval.
- Parameter userId: The retrieved user id.
*/
static func extractUserId(from: RouterRequest, completionHandler: (_ userId: String) -> Void)

Result

enter image description here enter image description here

Looks good enough for me!

like image 148
Shane Hsu Avatar answered Dec 15 '22 15:12

Shane Hsu