The handler closure must call the completionHandler to signal action completion.
Step 2: Check the given code
The closure ignores the third parameter (completionHandler) and does not call it, causing swipe to hang.
Final Answer:
Missing call to completionHandler inside the closure -> Option C
Quick Check:
Always call completionHandler in swipe action handler [OK]
Hint: Always call completionHandler(true/false) in handler closure [OK]
Common Mistakes:
Ignoring completionHandler call
Using wrong style enum (normal is valid here)
Thinking title case matters
Mixing closure parameter order
5. You want to add two swipe actions: "Flag" (normal style) and "Delete" (destructive style) to a table cell. Which code correctly creates and returns the swipe configuration?
hard
A. let flag = UIContextualAction(style: .normal, title: "Flag") { _, _, completion in completion(true) }
let delete = UIContextualAction(style: .destructive, title: "Delete") { _, _, completion in completion(true) }
return UISwipeActionsConfiguration(actions: [flag, delete])
B. let flag = UIContextualAction(style: .normal, title: "Flag") { _, _, completionHandler in completionHandler(true) }
let delete = UIContextualAction(style: .destructive, title: "Delete") { _, _, completionHandler in completionHandler(true) }
return UISwipeActionsConfiguration(actions: [flag, delete])
C. let flag = UIContextualAction(style: .normal, title: "Flag") { _, _, completionHandler in completionHandler(false) }
let delete = UIContextualAction(style: .destructive, title: "Delete") { _, _, completionHandler in completionHandler(true) }
return UISwipeActionsConfiguration(actions: [flag, delete])
D. let flag = UIContextualAction(style: .normal, title: "Flag") { _, _, completionHandler in completionHandler(true) }
let delete = UIContextualAction(style: .destructive, title: "Delete") { _, _, completionHandler in completionHandler(true) }
return UISwipeActionsConfiguration(actions: [delete, flag])
Solution
Step 1: Confirm action creation and completion calls
Both actions use correct styles and call completionHandler(true) to indicate success.
Step 2: Check order of actions in configuration
Swipe actions appear in order given; "Delete" usually placed first for prominence, then "Flag".
Final Answer:
Actions created with correct styles and completion calls; configuration returns [delete, flag] -> Option D
Quick Check:
Correct styles, completion calls, and order = let flag = UIContextualAction(style: .normal, title: "Flag") { _, _, completionHandler in completionHandler(true) }
let delete = UIContextualAction(style: .destructive, title: "Delete") { _, _, completionHandler in completionHandler(true) }
return UISwipeActionsConfiguration(actions: [delete, flag]) [OK]
Hint: Call completionHandler(true) and order destructive before normal [OK]
Common Mistakes:
Calling completionHandler(false) which cancels action
Using wrong variable name for completionHandler
Incorrect order of actions in array
Omitting completionHandler call
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.