From 2d05ff7c82bebd3d678ded77589178edf2209921 Mon Sep 17 00:00:00 2001 From: prabal4546 Date: Fri, 20 Aug 2021 00:44:19 +0530 Subject: [PATCH 1/4] swipe to delete --- .../Challenges/ChallengesDataSource.swift | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Unwrap/Activities/Challenges/ChallengesDataSource.swift b/Unwrap/Activities/Challenges/ChallengesDataSource.swift index 639b513d..fcb45495 100644 --- a/Unwrap/Activities/Challenges/ChallengesDataSource.swift +++ b/Unwrap/Activities/Challenges/ChallengesDataSource.swift @@ -73,4 +73,21 @@ class ChallengesDataSource: NSObject, UITableViewDataSource { return cell } } + //MARK:- Swipe to delete + func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { + if indexPath.section == 1{ + return true + }else{ + return false + } + } + func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) { + if indexPath.section == 1{ + if editingStyle == .delete{ + User.current.dailyChallenges.remove(at: indexPath.row) + tableView.reloadData() + } + + } + } } From 0984c96eb033a3e5896fbd126b5ef08ea8048636 Mon Sep 17 00:00:00 2001 From: prabal4546 Date: Fri, 20 Aug 2021 19:35:17 +0530 Subject: [PATCH 2/4] removed section-check conditional --- Unwrap/Activities/Challenges/ChallengesDataSource.swift | 3 --- 1 file changed, 3 deletions(-) diff --git a/Unwrap/Activities/Challenges/ChallengesDataSource.swift b/Unwrap/Activities/Challenges/ChallengesDataSource.swift index fcb45495..f98606fa 100644 --- a/Unwrap/Activities/Challenges/ChallengesDataSource.swift +++ b/Unwrap/Activities/Challenges/ChallengesDataSource.swift @@ -82,12 +82,9 @@ class ChallengesDataSource: NSObject, UITableViewDataSource { } } func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) { - if indexPath.section == 1{ if editingStyle == .delete{ User.current.dailyChallenges.remove(at: indexPath.row) tableView.reloadData() } - - } } } From 1ebca96f77c0fe1b718f30d82e610517d3e3a156 Mon Sep 17 00:00:00 2001 From: prabal4546 Date: Sun, 22 Aug 2021 09:57:17 +0530 Subject: [PATCH 3/4] trigger save --- Unwrap/Activities/Challenges/ChallengesDataSource.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Unwrap/Activities/Challenges/ChallengesDataSource.swift b/Unwrap/Activities/Challenges/ChallengesDataSource.swift index f98606fa..64768729 100644 --- a/Unwrap/Activities/Challenges/ChallengesDataSource.swift +++ b/Unwrap/Activities/Challenges/ChallengesDataSource.swift @@ -73,7 +73,7 @@ class ChallengesDataSource: NSObject, UITableViewDataSource { return cell } } - //MARK:- Swipe to delete + /// Swipe to delete func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { if indexPath.section == 1{ return true @@ -85,6 +85,7 @@ class ChallengesDataSource: NSObject, UITableViewDataSource { if editingStyle == .delete{ User.current.dailyChallenges.remove(at: indexPath.row) tableView.reloadData() + User.current.save() } } } From e8d7c0d5dd72edca039f6da5d5401c2566544e34 Mon Sep 17 00:00:00 2001 From: prabal4546 Date: Mon, 30 Aug 2021 18:43:39 +0530 Subject: [PATCH 4/4] minor fix --- Unwrap/Activities/Challenges/ChallengesDataSource.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Unwrap/Activities/Challenges/ChallengesDataSource.swift b/Unwrap/Activities/Challenges/ChallengesDataSource.swift index 64768729..70e1eb03 100644 --- a/Unwrap/Activities/Challenges/ChallengesDataSource.swift +++ b/Unwrap/Activities/Challenges/ChallengesDataSource.swift @@ -75,7 +75,7 @@ class ChallengesDataSource: NSObject, UITableViewDataSource { } /// Swipe to delete func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { - if indexPath.section == 1{ + if indexPath.section == 1 && User.current.dailyChallenges.count > 0{ return true }else{ return false