From 8e1c328252fbee8858e3b6b78c4172480ef99f75 Mon Sep 17 00:00:00 2001 From: ueunli Date: Tue, 7 Feb 2023 17:28:12 +0900 Subject: [PATCH 01/11] =?UTF-8?q?=20searchBar=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ListProfileViewController.swift | 28 +++++++++++++++++-- .../ContactManageSystem.swift | 19 +++---------- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/ios-cantact-manager/ContactManagerUI/Controllers/ListProfileViewController.swift b/ios-cantact-manager/ContactManagerUI/Controllers/ListProfileViewController.swift index 3151582a..60237796 100644 --- a/ios-cantact-manager/ContactManagerUI/Controllers/ListProfileViewController.swift +++ b/ios-cantact-manager/ContactManagerUI/Controllers/ListProfileViewController.swift @@ -12,6 +12,14 @@ final class ListProfileViewController: UIViewController, AddProfileViewControlle private var profiles: [Profile] { contactManageSystem.profiles.sorted(by: { $0.name < $1.name }) } + private lazy var filteredProfiles = [Profile]() + private var isSearching: Bool { + let searchBarController = self.navigationItem.searchController + let isActive = searchBarController?.isActive ?? false + let isEmpty = searchBarController?.searchBar.text?.isEmpty ?? false + return isActive && !isEmpty + } + private let dummyData = [ Profile(name: "james", age: "30", tel: "010-2222-2222"), Profile(name: "tom", age: "15", tel: "010-2222-3333"), @@ -28,6 +36,7 @@ final class ListProfileViewController: UIViewController, AddProfileViewControlle contactManageSystem.add(profile: $0) } tableView.dataSource = self + makeSearchBar() } @IBAction private func addProfileButtonDidTap(_ sender: UIBarButtonItem) { @@ -47,11 +56,11 @@ final class ListProfileViewController: UIViewController, AddProfileViewControlle extension ListProfileViewController: UITableViewDataSource { func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - profiles.count + isSearching ? filteredProfiles.count : profiles.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let profile = profiles[indexPath.row] + let profile = isSearching ? filteredProfiles[indexPath.row] : profiles[indexPath.row] let cell = tableView.dequeueReusableCell(withIdentifier: "ProfileCell", for: indexPath) var content = cell.defaultContentConfiguration() @@ -65,3 +74,18 @@ extension ListProfileViewController: UITableViewDataSource { } } +extension ListProfileViewController: UISearchResultsUpdating { + func makeSearchBar() { + let searchBar = UISearchController(searchResultsController: nil) + searchBar.searchResultsUpdater = self + self.navigationItem.searchController = searchBar + self.navigationItem.hidesSearchBarWhenScrolling = true //TODO: - self들 정리(전체적으로) + self.navigationItem.searchController?.searchBar.autocapitalizationType = .none //TODO: - 자동 대문자화 해제(정리 필요) + } + + func updateSearchResults(for searchController: UISearchController) { + guard let text = searchController.searchBar.text else { return } + self.filteredProfiles = self.profiles.filter { $0.name == text } //TODO: - 대소문자 상관x + tableView.reloadData() + } +} diff --git a/ios-cantact-manager/ios-cantact-manager/ContactManageSystem.swift b/ios-cantact-manager/ios-cantact-manager/ContactManageSystem.swift index 3361ad51..6a2d99e3 100644 --- a/ios-cantact-manager/ios-cantact-manager/ContactManageSystem.swift +++ b/ios-cantact-manager/ios-cantact-manager/ContactManageSystem.swift @@ -49,7 +49,7 @@ struct ContactManageSystem { case .listUpProfile: listUpProfile() case .searchProfile: - searchProfile() + break case .stop: stop() } @@ -63,20 +63,9 @@ struct ContactManageSystem { OutputManager.print(profiles: profiles) } - private func searchProfile() { - do { - OutputManager.print(text: .inputProfileName) - let targetName = try inputManager.targetInput() - let filteredProfileData = profiles.filter { $0.name == targetName } - guard !filteredProfileData.isEmpty else { - OutputManager.printNoMatchingData(name: targetName) - return - } - OutputManager.print(profiles: filteredProfileData) - } catch { - OutputManager.print(text: .invalidInput) - } - } +// func searchProfile(name: String) -> [Profile] { +// profiles.filter { $0.name == name } +// } mutating func stop() { OutputManager.print(text: .stopSystem) From 0df0cf76e6c3975c19ca98f3904c67a07de0456c Mon Sep 17 00:00:00 2001 From: ueunli Date: Wed, 8 Feb 2023 11:33:39 +0900 Subject: [PATCH 02/11] =?UTF-8?q?=20searchBar=20=EA=B5=AC=ED=98=84?= =?UTF-8?q?=EB=B6=80=20=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 불필요한 표현(self) 및 접근 삭제 - 대소문자 상관 없이 검색되도록 개선 --- .../Controllers/ListProfileViewController.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ios-cantact-manager/ContactManagerUI/Controllers/ListProfileViewController.swift b/ios-cantact-manager/ContactManagerUI/Controllers/ListProfileViewController.swift index 60237796..3dfec66a 100644 --- a/ios-cantact-manager/ContactManagerUI/Controllers/ListProfileViewController.swift +++ b/ios-cantact-manager/ContactManagerUI/Controllers/ListProfileViewController.swift @@ -78,14 +78,14 @@ extension ListProfileViewController: UISearchResultsUpdating { func makeSearchBar() { let searchBar = UISearchController(searchResultsController: nil) searchBar.searchResultsUpdater = self - self.navigationItem.searchController = searchBar - self.navigationItem.hidesSearchBarWhenScrolling = true //TODO: - self들 정리(전체적으로) - self.navigationItem.searchController?.searchBar.autocapitalizationType = .none //TODO: - 자동 대문자화 해제(정리 필요) + searchBar.searchBar.autocapitalizationType = .none + navigationItem.searchController = searchBar + navigationItem.hidesSearchBarWhenScrolling = true } func updateSearchResults(for searchController: UISearchController) { guard let text = searchController.searchBar.text else { return } - self.filteredProfiles = self.profiles.filter { $0.name == text } //TODO: - 대소문자 상관x + filteredProfiles = profiles.filter { $0.name.lowercased() == text.lowercased() } tableView.reloadData() } } From e4d0bdb4ad10a39ff6cb92b7fb32b9d802ab7036 Mon Sep 17 00:00:00 2001 From: ueunli Date: Wed, 8 Feb 2023 12:56:12 +0900 Subject: [PATCH 03/11] =?UTF-8?q?=20swipe=ED=95=98=EC=97=AC=20?= =?UTF-8?q?=ED=94=84=EB=A1=9C=ED=95=84=20=EC=82=AD=EC=A0=9C=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - UITableViewDelegate 채택 --- .../Controllers/ListProfileViewController.swift | 11 +++++++++++ .../ios-cantact-manager/ContactManageSystem.swift | 6 +++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/ios-cantact-manager/ContactManagerUI/Controllers/ListProfileViewController.swift b/ios-cantact-manager/ContactManagerUI/Controllers/ListProfileViewController.swift index 3dfec66a..b6a31ded 100644 --- a/ios-cantact-manager/ContactManagerUI/Controllers/ListProfileViewController.swift +++ b/ios-cantact-manager/ContactManagerUI/Controllers/ListProfileViewController.swift @@ -89,3 +89,14 @@ extension ListProfileViewController: UISearchResultsUpdating { tableView.reloadData() } } + +extension ListProfileViewController: UITableViewDelegate { + func tableView(_ tableView: UITableView, + commit editingStyle: UITableViewCell.EditingStyle, + forRowAt indexPath: IndexPath) { + guard editingStyle == .delete else { return } + let profile = isSearching ? filteredProfiles[indexPath.row] : profiles[indexPath.row] + contactManageSystem.remove(profile: profile) + tableView.deleteRows(at: [indexPath], with: .fade) + } +} diff --git a/ios-cantact-manager/ios-cantact-manager/ContactManageSystem.swift b/ios-cantact-manager/ios-cantact-manager/ContactManageSystem.swift index 6a2d99e3..d0f82906 100644 --- a/ios-cantact-manager/ios-cantact-manager/ContactManageSystem.swift +++ b/ios-cantact-manager/ios-cantact-manager/ContactManageSystem.swift @@ -63,9 +63,9 @@ struct ContactManageSystem { OutputManager.print(profiles: profiles) } -// func searchProfile(name: String) -> [Profile] { -// profiles.filter { $0.name == name } -// } + mutating func remove(profile: Profile) { + profiles.remove(profile) + } mutating func stop() { OutputManager.print(text: .stopSystem) From 751f1c3770e7fb1b4f9f3fbc5a30212a7074e4d8 Mon Sep 17 00:00:00 2001 From: ueunli Date: Wed, 8 Feb 2023 15:17:07 +0900 Subject: [PATCH 04/11] =?UTF-8?q?=20=EB=8D=94=EB=AF=B8=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=84=B0,=20=EC=A0=95=EB=A0=AC=EA=B8=B0=EC=A4=80,=20?= =?UTF-8?q?=EC=84=9C=EC=B9=98=EB=B0=94=20=EC=88=A8=EA=B8=B0=EA=B8=B0=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 동명이인일 경우에도 정확히 삭제되는지 확인하기 쉬운 더미데이터로 변경 - 동명이인일 경우 나이순으로 정렬되도록 수정 - 아래로 스크롤해도 서치바가 보이도록 처리 --- .../ListProfileViewController.swift | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/ios-cantact-manager/ContactManagerUI/Controllers/ListProfileViewController.swift b/ios-cantact-manager/ContactManagerUI/Controllers/ListProfileViewController.swift index b6a31ded..da2cf91b 100644 --- a/ios-cantact-manager/ContactManagerUI/Controllers/ListProfileViewController.swift +++ b/ios-cantact-manager/ContactManagerUI/Controllers/ListProfileViewController.swift @@ -10,7 +10,10 @@ import UIKit final class ListProfileViewController: UIViewController, AddProfileViewControllerDelegate { private var contactManageSystem = ContactManageSystem() private var profiles: [Profile] { - contactManageSystem.profiles.sorted(by: { $0.name < $1.name }) + contactManageSystem.profiles.sorted { + let (lhs, rhs) = ($0.name.lowercased(), $1.name.lowercased()) + return lhs != rhs ? lhs < rhs : $0.age < $1.age + } } private lazy var filteredProfiles = [Profile]() private var isSearching: Bool { @@ -21,11 +24,16 @@ final class ListProfileViewController: UIViewController, AddProfileViewControlle } private let dummyData = [ - Profile(name: "james", age: "30", tel: "010-2222-2222"), - Profile(name: "tom", age: "15", tel: "010-2222-3333"), - Profile(name: "jams", age: "30", tel: "010-2222-2222"), - Profile(name: "toem", age: "15", tel: "010-2222-3333"), - Profile(name: "jamses", age: "30", tel: "010-2222-2222") + Profile(name: "iyeah", age: "1", tel: "010-2222-2222"), + Profile(name: "iyeah", age: "2", tel: "010-2222-3333"), + Profile(name: "iyeah", age: "3", tel: "010-2222-2222"), + Profile(name: "iyeah", age: "4", tel: "010-2222-3333"), + Profile(name: "Jenna", age: "5", tel: "010-2222-3333"), + Profile(name: "Jenna", age: "6", tel: "010-2222-3333"), + Profile(name: "Jenna", age: "7", tel: "010-2222-3333"), + Profile(name: "Jenna", age: "8", tel: "010-2222-3333"), + Profile(name: "iyeah", age: "9", tel: "010-2222-3333"), + Profile(name: "SeSaC", age: "30", tel: "010-2222-2222") ] @IBOutlet private weak var tableView: UITableView! @@ -80,7 +88,7 @@ extension ListProfileViewController: UISearchResultsUpdating { searchBar.searchResultsUpdater = self searchBar.searchBar.autocapitalizationType = .none navigationItem.searchController = searchBar - navigationItem.hidesSearchBarWhenScrolling = true + navigationItem.hidesSearchBarWhenScrolling = false } func updateSearchResults(for searchController: UISearchController) { From bedfcb8b240cbd35933708a09f222afa8b31bfb5 Mon Sep 17 00:00:00 2001 From: iyeahh Date: Thu, 9 Feb 2023 10:32:52 +0900 Subject: [PATCH 05/11] =?UTF-8?q?=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EC=9C=84=EC=B9=98=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ListProfileViewController.swift | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/ios-cantact-manager/ContactManagerUI/Controllers/ListProfileViewController.swift b/ios-cantact-manager/ContactManagerUI/Controllers/ListProfileViewController.swift index da2cf91b..1f47174a 100644 --- a/ios-cantact-manager/ContactManagerUI/Controllers/ListProfileViewController.swift +++ b/ios-cantact-manager/ContactManagerUI/Controllers/ListProfileViewController.swift @@ -80,6 +80,15 @@ extension ListProfileViewController: UITableViewDataSource { return cell } + + func tableView(_ tableView: UITableView, + commit editingStyle: UITableViewCell.EditingStyle, + forRowAt indexPath: IndexPath) { + guard editingStyle == .delete else { return } + let profile = isSearching ? filteredProfiles[indexPath.row] : profiles[indexPath.row] + contactManageSystem.remove(profile: profile) + tableView.deleteRows(at: [indexPath], with: .fade) + } } extension ListProfileViewController: UISearchResultsUpdating { @@ -97,14 +106,3 @@ extension ListProfileViewController: UISearchResultsUpdating { tableView.reloadData() } } - -extension ListProfileViewController: UITableViewDelegate { - func tableView(_ tableView: UITableView, - commit editingStyle: UITableViewCell.EditingStyle, - forRowAt indexPath: IndexPath) { - guard editingStyle == .delete else { return } - let profile = isSearching ? filteredProfiles[indexPath.row] : profiles[indexPath.row] - contactManageSystem.remove(profile: profile) - tableView.deleteRows(at: [indexPath], with: .fade) - } -} From 7265e30729cbdf6457f5aa44e8192e3d70f7ad27 Mon Sep 17 00:00:00 2001 From: ueunli Date: Thu, 9 Feb 2023 17:05:23 +0900 Subject: [PATCH 06/11] =?UTF-8?q?=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EC=A0=91=EA=B7=BC=EC=A0=9C=EC=96=B4=EC=9E=90=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - `makeSearchBar()`를 private func로 수정 - extension 내 두 메서드의 순서 교체 (private이 밑으로 오도록) - `tableView(_:commit:forRowAt:)`메서드의 불필요한 로직 생략 --- .../Controllers/ListProfileViewController.swift | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/ios-cantact-manager/ContactManagerUI/Controllers/ListProfileViewController.swift b/ios-cantact-manager/ContactManagerUI/Controllers/ListProfileViewController.swift index 1f47174a..9ff67c85 100644 --- a/ios-cantact-manager/ContactManagerUI/Controllers/ListProfileViewController.swift +++ b/ios-cantact-manager/ContactManagerUI/Controllers/ListProfileViewController.swift @@ -84,7 +84,6 @@ extension ListProfileViewController: UITableViewDataSource { func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) { - guard editingStyle == .delete else { return } let profile = isSearching ? filteredProfiles[indexPath.row] : profiles[indexPath.row] contactManageSystem.remove(profile: profile) tableView.deleteRows(at: [indexPath], with: .fade) @@ -92,17 +91,17 @@ extension ListProfileViewController: UITableViewDataSource { } extension ListProfileViewController: UISearchResultsUpdating { - func makeSearchBar() { + func updateSearchResults(for searchController: UISearchController) { + guard let text = searchController.searchBar.text else { return } + filteredProfiles = profiles.filter { $0.name.lowercased() == text.lowercased() } + tableView.reloadData() + } + + private func makeSearchBar() { let searchBar = UISearchController(searchResultsController: nil) searchBar.searchResultsUpdater = self searchBar.searchBar.autocapitalizationType = .none navigationItem.searchController = searchBar navigationItem.hidesSearchBarWhenScrolling = false } - - func updateSearchResults(for searchController: UISearchController) { - guard let text = searchController.searchBar.text else { return } - filteredProfiles = profiles.filter { $0.name.lowercased() == text.lowercased() } - tableView.reloadData() - } } From fe3f6b087857790c2e181c20898ffaf71109d4f2 Mon Sep 17 00:00:00 2001 From: Junely <67406889+ueunli@users.noreply.github.com> Date: Fri, 10 Feb 2023 10:55:58 +0900 Subject: [PATCH 07/11] =?UTF-8?q?=20README.md=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 121 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 120 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 14895eae..5f86aa79 100644 --- a/README.md +++ b/README.md @@ -1 +1,120 @@ -# ios-contact-manager-ui \ No newline at end of file +# 🗓 README +#### ✨ iyeah & 🍏 Jenna
+##### 2023년 1월 30일 → 2023년 2월 10일 + +  + +# Step 1️⃣ +## \# 트러블 슈팅 +### 👿 트러블 +> 기존 프로젝트 코드를 가져오면서, 프로젝트 및 폴더명을 바꿔야 할 지 고민 + +### 😈 해결 방법 +> 타겟 `ContactManagerUI`을 새로 추가한다는 것은 프로젝트에 별도의 제품을 만든다는 것이므로, +오히려 이름을 같게 맞추려 할 필요가 없음을 깨달아 프로젝트 및 폴더명 유지 + + +## \# 학습내용 요약 +>`Target` +하나의 타겟은 하나의 프로덕트이며, +프로젝트 내에 여러 개의(= 별개의) 타겟(프로덕트)이 존재할 수 있다. + + + +  +   +
+# Step 2️⃣ +## \# 트러블 슈팅 +### 👿 트러블 +> 더미 데이터를 Model인 `ContactManageSystem`에 넣을지, `ViewController`에 구현 해야할 지에 대한 고민 + +### 😈 해결 방법 +
+리뷰어 의견 🐶 +더미 데이터 자체를 상수처럼 만들어서 ViewController에서 처리하는게 저는 더 깔끔한 것 같아요! 상수처럼 쓰고 나중에 제거하면 되니까요! +
+ +→ `ViewController`에 `dummyData`를 상수로 선언하여 해결 + +  +### 👿 트러블 +> MVC 폴더에 넣기 애매한 파일들 처리 + +### 😈 해결 방법 +
+리뷰어 의견 🐶 +이 부분은 정해져있는 답은 없으니, 팀 내에서 약속해서 폴더로 정리해도 괜찮습니다.
MVC 폴더 밖으로 빼두는 것도 좋습니다.
LaunchScreen을 따로 폴더로 만드는 경우도 있고, AppConfiguration과 같이 폴더를 만들어서 AppDelegate, SceneDelegate 파일을 넣기도합니다.
제가 말씀드린 부분은 참고만하시고 팀원과 같이 이야기해보면 좋을 것 같습니다:) +
+ +→ 아래와 같이 폴더링 진행 + +![](https://i.imgur.com/cUjN62R.png) + + +  +## \# 학습내용 요약 +> 1. 더미데이터가 필요하다면 원하는 시점에 삭제가 편하도록 상수로 구현 +> 2. 폴더링은 정해진 게 없기 때문에 팀원과 상의해서 정하기 + + + +
+# Step 3️⃣ +## \# 트러블 슈팅 +### 👿 트러블 +> `.phonePad`는 -입력을 지원하지 않음 +→ 아이폰 기본앱처럼, 텍스트필드에 값이 입력될 때마다 `-`가 적절한 위치에 삽입되게끔 자동변환 해주는 로직을 추가로 구현할 필요가 생김 + +### 😈 해결 방법 +> `textField(_:shouldChangeCharactersIn:replacementString:)`메서드 + +- `AddProfileViewController가` `UITextFieldDelegate`프로토콜을 채택 +- `textField(_:shouldChangeCharactersIn:replacementString:)`메서드로 새로운 입력의 종류에 따라 + - 연락처 텍스트필드에서의 입력을 허용하거나, + - 또는 양식에 맞춘 변환값으로 대체하여 직접 할당(입력 거절) +- `PhoneNumberRegularExpressions`열거형으로 자릿수별 변환 방식을 정의 + +  +## \# 학습내용 요약 +> Delegate의 정의는 `위임하다`, +개인적으로 Delegate Pattern이란 `책임자-대리자 패턴` 이라고 이해 +#### 프로젝트에 적용한 부분 ▼ +- `AddProfileViewController`(이하 AddVC)는 **책임자** +- `ListProfileViewController`(이하 ListVC)는 `AddProfileViewControllerDelegate`(이하 AddVCDelegate) 자격증을 가짐 +- `ListVC`는 새로운 뷰(`AddV`)를 올릴 때 본인(self)을 그 뷰컨트롤러(`AddVC`)의 **대리자**(Delegate)로 지정하여 함께 보내지고, + ```Swift + AddVC.delegate: AddVCDelegate = self //self: ListVC(AddVCDelegate로서의 ListVC) + ``` +- 대리자는 책임자(AddVC) 내에 머물며(= .delegate변수에 할당된 채) +대리자로서 요구받은 동작(프로토콜 필수구현 메서드)을 적절한 시점에 수행 + ```Swift + // 그 동작은 AddProfileViewController에서 'Save버튼이 눌렀을 때' 호출되어, + // (검증 완료된) 새로운 이름·나이·연락처 정보를 조합하여 프로필을 생성(= 요구받은 동작) + delegate?.updateProfile(name: name, age: age, tel: tel) + dismiss() + ``` +- `AddV`가 내려가면 대리자 역할을 마무리하고 돌아온 `ListVC`는 그 데이터(새 프로필)를 받아 필요한 작업(profiles에 새 프로필을 등록)을 이어서 수행 + + + +  +  +
+# Step 🅱🅾🅽🆄🆂 +## \# 트러블 슈팅 +### 👿 트러블 +> (작성중) + + +### 😈 해결 방법 +> (작성중) + + +  +## \# 학습내용 요약 +(정리중) + + +  +   From ab0ef289d7916e75b7ed9046cad64aa4596460ca Mon Sep 17 00:00:00 2001 From: Junely <67406889+ueunli@users.noreply.github.com> Date: Fri, 10 Feb 2023 10:57:41 +0900 Subject: [PATCH 08/11] =?UTF-8?q?=20README.md=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5f86aa79..016c83dc 100644 --- a/README.md +++ b/README.md @@ -57,9 +57,10 @@ > 1. 더미데이터가 필요하다면 원하는 시점에 삭제가 편하도록 상수로 구현 > 2. 폴더링은 정해진 게 없기 때문에 팀원과 상의해서 정하기 + +
-
# Step 3️⃣ ## \# 트러블 슈팅 ### 👿 트러블 From c0ce3cb517a571fe99be1bab9f0351944119e72b Mon Sep 17 00:00:00 2001 From: iyeahh Date: Fri, 10 Feb 2023 13:06:16 +0900 Subject: [PATCH 09/11] =?UTF-8?q?=20=EA=B0=80=EB=8F=85=EC=84=B1=20?= =?UTF-8?q?=EA=B0=9C=EC=84=A0=20=EC=9C=84=ED=95=9C=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EA=B0=9C=ED=96=89,=20=EB=84=A4=EC=9D=B4=EB=B0=8D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ListProfileViewController.swift | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/ios-cantact-manager/ContactManagerUI/Controllers/ListProfileViewController.swift b/ios-cantact-manager/ContactManagerUI/Controllers/ListProfileViewController.swift index 9ff67c85..afb5ff9d 100644 --- a/ios-cantact-manager/ContactManagerUI/Controllers/ListProfileViewController.swift +++ b/ios-cantact-manager/ContactManagerUI/Controllers/ListProfileViewController.swift @@ -15,11 +15,11 @@ final class ListProfileViewController: UIViewController, AddProfileViewControlle return lhs != rhs ? lhs < rhs : $0.age < $1.age } } - private lazy var filteredProfiles = [Profile]() + private lazy var profileSearchResults = [Profile]() private var isSearching: Bool { let searchBarController = self.navigationItem.searchController let isActive = searchBarController?.isActive ?? false - let isEmpty = searchBarController?.searchBar.text?.isEmpty ?? false + let isEmpty = searchBarController?.searchBar.text?.isEmpty ?? true return isActive && !isEmpty } @@ -64,11 +64,11 @@ final class ListProfileViewController: UIViewController, AddProfileViewControlle extension ListProfileViewController: UITableViewDataSource { func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - isSearching ? filteredProfiles.count : profiles.count + isSearching ? profileSearchResults.count : profiles.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let profile = isSearching ? filteredProfiles[indexPath.row] : profiles[indexPath.row] + let profile = isSearching ? profileSearchResults[indexPath.row] : profiles[indexPath.row] let cell = tableView.dequeueReusableCell(withIdentifier: "ProfileCell", for: indexPath) var content = cell.defaultContentConfiguration() @@ -84,7 +84,7 @@ extension ListProfileViewController: UITableViewDataSource { func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) { - let profile = isSearching ? filteredProfiles[indexPath.row] : profiles[indexPath.row] + let profile = isSearching ? profileSearchResults[indexPath.row] : profiles[indexPath.row] contactManageSystem.remove(profile: profile) tableView.deleteRows(at: [indexPath], with: .fade) } @@ -92,8 +92,12 @@ extension ListProfileViewController: UITableViewDataSource { extension ListProfileViewController: UISearchResultsUpdating { func updateSearchResults(for searchController: UISearchController) { - guard let text = searchController.searchBar.text else { return } - filteredProfiles = profiles.filter { $0.name.lowercased() == text.lowercased() } + guard let text = searchController.searchBar.text else { + return + } + profileSearchResults = profiles.filter { + $0.name.lowercased() == text.lowercased() + } tableView.reloadData() } From e544c0dd97d291cd27c62098fbbecb3197853f76 Mon Sep 17 00:00:00 2001 From: ueunli Date: Fri, 10 Feb 2023 13:13:01 +0900 Subject: [PATCH 10/11] =?UTF-8?q?=20=EB=B3=B5=EC=9E=A1=ED=95=9C?= =?UTF-8?q?=20=EB=A1=9C=EC=A7=81=EC=9D=84=20=EB=AA=A8=EB=8D=B8=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EC=B2=98=EB=A6=AC=ED=95=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - `ContactManageSystem`에 이름, 나이순으로 정렬하는 메서드 `sortProfiles()`를 추가 --- .../Controllers/ListProfileViewController.swift | 5 +---- .../ios-cantact-manager/ContactManageSystem.swift | 7 +++++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/ios-cantact-manager/ContactManagerUI/Controllers/ListProfileViewController.swift b/ios-cantact-manager/ContactManagerUI/Controllers/ListProfileViewController.swift index afb5ff9d..144f8833 100644 --- a/ios-cantact-manager/ContactManagerUI/Controllers/ListProfileViewController.swift +++ b/ios-cantact-manager/ContactManagerUI/Controllers/ListProfileViewController.swift @@ -10,10 +10,7 @@ import UIKit final class ListProfileViewController: UIViewController, AddProfileViewControllerDelegate { private var contactManageSystem = ContactManageSystem() private var profiles: [Profile] { - contactManageSystem.profiles.sorted { - let (lhs, rhs) = ($0.name.lowercased(), $1.name.lowercased()) - return lhs != rhs ? lhs < rhs : $0.age < $1.age - } + contactManageSystem.sortProfiles() } private lazy var profileSearchResults = [Profile]() private var isSearching: Bool { diff --git a/ios-cantact-manager/ios-cantact-manager/ContactManageSystem.swift b/ios-cantact-manager/ios-cantact-manager/ContactManageSystem.swift index d0f82906..a2f56b86 100644 --- a/ios-cantact-manager/ios-cantact-manager/ContactManageSystem.swift +++ b/ios-cantact-manager/ios-cantact-manager/ContactManageSystem.swift @@ -59,6 +59,13 @@ struct ContactManageSystem { profiles.insert(profile) } + mutating func sortProfiles() -> [Profile] { + profiles.sorted { + let (lhs, rhs) = ($0.name.lowercased(), $1.name.lowercased()) + return lhs != rhs ? lhs < rhs : $0.age < $1.age + } + } + private func listUpProfile() { OutputManager.print(profiles: profiles) } From e4941945a4998f1d32f8c5ab905a501a99b839d2 Mon Sep 17 00:00:00 2001 From: Junely <67406889+ueunli@users.noreply.github.com> Date: Fri, 10 Feb 2023 14:13:55 +0900 Subject: [PATCH 11/11] =?UTF-8?q?=20README.md=20=EB=82=B4=EC=9A=A9?= =?UTF-8?q?=20=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 016c83dc..793990a6 100644 --- a/README.md +++ b/README.md @@ -102,19 +102,47 @@    
+ # Step 🅱🅾🅽🆄🆂 ## \# 트러블 슈팅 ### 👿 트러블 -> (작성중) +> 검색결과 화면에서도 올바른 셀이 삭제되도록 하기 +### 😈 해결 방법 +삼항연산자를 활용하여, `isSearching`에 따라 +index로 접근할 프로필 배열이 `profiles` / `filteredProfiles` 중 어느쪽인지 결정하는 로직을 추가 +```Swift +let profile = isSearching ? profileSearchResults[indexPath.row] : profiles[indexPath.row] +``` + +  +### 👿 트러블 +> 동명이인이 있어도 정확히 삭제되도록 하기 ### 😈 해결 방법 -> (작성중) +1. 초반에 profiles에서 `name`이 일치하는 결과를 가져오려고 했지만, 동명이인이 대신 삭제되는 문제가 발생 +2. Model인 `Profile`이 Hashable프로토콜(= 즉 Equatable도 채택함)을 채택했으므로 커스텀 이항연산자를 구현해보려다가 아래와 같은 발상이 떠올라 보류 +3. `tableView(_:cellForRowAt:)`메서드에서 `indexPath.row`로 `profile`을 불러왔으므로, 역으로 해당 index의 profile을 꺼내어 삭제하면 해당 셀의 profile이 삭제될 거라고 생각하고 구현 +  +### 👿 트러블 +> 이름에 대소문자가 섞여 있을 때 오름차순으로 올바르게 정렬되지 않고 검색이 되지 않음 +### 😈 해결 방법 +오름차순 정렬 시 `lowercased()` 메서드를 적용하여 대소문자 구분없이 sort되도록 함 + +    ## \# 학습내용 요약 -(정리중) +### searchBar 만들기 +> **UISearchBar와 UISearchController의 차이** +> - VC.navigationItem.searchController: `UISearchController` +> - UISearchController().searchBar: `UISearchBar` +### 슬라이드하여 해당 셀 delete 하기 +> `UITableViewDataSource` 프로토콜 내에 있는 `tableView(_:commit:forRowAt:)` 메서드 사용 + + +