How to explain completionHandler(true) or (false)

I am following a tutorial online regarding a TableView Cell swipe action.


override func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {


let like = UIContextualAction(style: .normal, title: "Like") { (_, _, isComplete) in


self.favStatusCollection[indexPath.row] = !self.favStatusCollection[indexPath.row]

// Call completion handler to dismiss the action button

isComplete(true)

}



However, if I call isComplete(false) instead of isComplete(true). It makes no difference in action in the running test.

Answered by OOPer in 407587022

The header doc of `UIContextualActionHandler` (in UIContextualAction.h) says:


pass YES to the completionHandler if the action was actually performed, to show a visual indication of the successful completion


But, as far as I tested, I cannot find any visual indications when returnning true, compared to returning false.

(I found some articles saying that some early versions of iOS 11 showed different behavior, but that was considered to be a bug and fixed.)


iOS might be using the value internally (or may use it in the future), so you should better pass the appropriate value:

true: for the action actually performed, false: otherwise

even if it makes no difference.

The closure is called when the user taps the action and has action, source view and completion handler arguments.

You call the completion handler (isComplete)with

true
to indicate you performed the action or
false
if you could not for some reason.


See here for details:

h ttps://useyourloaf.com/blog/table-swipe-actions/

Accepted Answer

The header doc of `UIContextualActionHandler` (in UIContextualAction.h) says:


pass YES to the completionHandler if the action was actually performed, to show a visual indication of the successful completion


But, as far as I tested, I cannot find any visual indications when returnning true, compared to returning false.

(I found some articles saying that some early versions of iOS 11 showed different behavior, but that was considered to be a bug and fixed.)


iOS might be using the value internally (or may use it in the future), so you should better pass the appropriate value:

true: for the action actually performed, false: otherwise

even if it makes no difference.

See a clear explanation here on how to use true or false


https://stackoverflow.com/questions/55316223/how-to-explain-completionhandlertrue

I'm afraid, my key question is just the same as the last answer in "https://stackoverflow.com/questions/55316223/how-to-explain-completionhandlertrue"

I just begin to learn swift. Where can I find "The header doc of `UIContextualActionHandler` (in UIContextualAction.h)"

Command-click on `UIContextualAction` in the editor window of Xcode, and select Jump to Definition.


You can see the imported header of the class in Swift.


And the click the four square icon at the left top of the editor windows and choose Original Source.


You can find the original header in Objective-C like following:

// call the completionHandler to reset the context to its normal state (e.g. when swiping, resets to unswiped state)
// pass YES to the completionHandler if the action was actually performed, to show a visual indication of the successful completion
typedef void (^UIContextualActionHandler)(UIContextualAction *action, __kindof UIView *sourceView, void(^completionHandler)(BOOL actionPerformed));

(You may need to guess that `UIContextualActionHandler` is the counter part type in ObjC for `UIContextualAction.Handler` in Swift.


In some cases, you will find useful info which is not included in the official doc for Swift.

Thanks a lot🙂

How to explain completionHandler(true) or (false)
 
 
Q