Skip to content

Commit f919552

Browse files
authored
Merge pull request #200 from prabal4546/main
Swipe to Delete
2 parents 52d0a7a + e8d7c0d commit f919552

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Unwrap/Activities/Challenges/ChallengesDataSource.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,19 @@ class ChallengesDataSource: NSObject, UITableViewDataSource {
7373
return cell
7474
}
7575
}
76+
/// Swipe to delete
77+
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
78+
if indexPath.section == 1 && User.current.dailyChallenges.count > 0{
79+
return true
80+
}else{
81+
return false
82+
}
83+
}
84+
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
85+
if editingStyle == .delete{
86+
User.current.dailyChallenges.remove(at: indexPath.row)
87+
tableView.reloadData()
88+
User.current.save()
89+
}
90+
}
7691
}

0 commit comments

Comments
 (0)