Bird
0
0

Identify the error in this code snippet inside tableView(_:leadingSwipeActionsConfigurationForRowAt:):

medium📝 Debug Q6 of 15
iOS Swift - Lists and Data Display
Identify the error in this code snippet inside tableView(_:leadingSwipeActionsConfigurationForRowAt:):
let editAction = UIContextualAction(style: .normal, title: "Edit") { action, view, completion in
    print("Edit tapped")
    completion()
}
return UISwipeActionsConfiguration(actions: [editAction])
AUIContextualAction style .normal is invalid
BThe completion handler is called without a Bool parameter
CThe title parameter must be nil for .normal style
DUISwipeActionsConfiguration requires at least two actions
Step-by-Step Solution
Solution:
  1. Step 1: Check completion handler signature

    The completion closure requires a Bool parameter indicating success or failure.
  2. Step 2: Identify incorrect call

    Calling completion() without argument causes a compile error.
  3. Final Answer:

    The completion handler is called without a Bool parameter -> Option B
  4. Quick Check:

    completion must be called with true or false [OK]
Quick Trick: Always call completion(true) or completion(false) in swipe action handlers [OK]
Common Mistakes:
  • Calling completion without argument
  • Using invalid style values
  • Assuming multiple actions are mandatory

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes