From c83e9b748d0257ad70773271dd65f380f792463a Mon Sep 17 00:00:00 2001 From: Yoonseo Kim Date: Fri, 24 Sep 2021 17:23:41 +0900 Subject: [PATCH] =?UTF-8?q?[#5]=20=E1=84=87=E1=85=AE=E1=86=AF=E1=84=91?= =?UTF-8?q?=E1=85=B5=E1=86=AF=E1=84=8B=E1=85=AD=E1=84=92=E1=85=A1=E1=86=AB?= =?UTF-8?q?=20Observing=20=E1=84=8C=E1=85=A6=E1=84=80=E1=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/ViewModels/MainViewModel.swift | 20 ++++++++++--------- .../Views/MainTableViewController.swift | 12 +++++------ 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/CheoMooRac/CheoMooRac/Sources/ViewModels/MainViewModel.swift b/CheoMooRac/CheoMooRac/Sources/ViewModels/MainViewModel.swift index fc127aa..8e96e66 100644 --- a/CheoMooRac/CheoMooRac/Sources/ViewModels/MainViewModel.swift +++ b/CheoMooRac/CheoMooRac/Sources/ViewModels/MainViewModel.swift @@ -15,10 +15,11 @@ protocol MainViewModelInput { protocol MainViewModelOutput { var list: Dynamic<[Person]> {get} - var sectionHeaderList: Dynamic<[String]> {get} var nowRefreshing: Dynamic {get} var isFiltering: Dynamic {get} - func getSectionArray(at section: Int) -> Dynamic<[String]> + + var sectionHeaderList: [String] {get} + func getSectionArray(at section: Int) -> [String] } protocol MainViewModelProtocol : MainViewModelInput, MainViewModelOutput {} @@ -38,7 +39,7 @@ class MainViewModel: MainViewModelProtocol { isFiltering.value = false setTableView() } else { - self.sectionHeaderList.value.removeAll() + self.sectionHeaderList.removeAll() self.list.value.removeAll() isFiltering.value = true @@ -53,7 +54,7 @@ class MainViewModel: MainViewModelProtocol { filterdHeaderList$ = Array(Set(filterdHeaderList$)).sorted() filteredData = filteredArr list.value = filteredData - sectionHeaderList.value = filterdHeaderList$ + sectionHeaderList = filterdHeaderList$ } } @@ -65,15 +66,16 @@ class MainViewModel: MainViewModelProtocol { // MARK: - OUTPUT let list: Dynamic<[Person]> = Dynamic([]) - let sectionHeaderList: Dynamic<[String]> = Dynamic([]) let nowRefreshing: Dynamic = Dynamic(false) let isFiltering: Dynamic = Dynamic(false) - func getSectionArray(at section: Int) -> Dynamic<[String]> { - return Dynamic(sectionArray(at: section, data: isFiltering.value ? self.filteredData : self.data)) + func getSectionArray(at section: Int) -> [String] { + return sectionArray(at: section, data: isFiltering.value ? self.filteredData : self.data) } + var sectionHeaderList: [String] = [] + init() { setTableView() @@ -110,12 +112,12 @@ class MainViewModel: MainViewModelProtocol { self.list.value.forEach { person in sectionHeaderList$.append(StringManager.shared.chosungCheck(word: person.familyName + person.firstName)) } - self.sectionHeaderList.value = Array(Set(sectionHeaderList$)).sorted() + self.sectionHeaderList = Array(Set(sectionHeaderList$)).sorted() } private func sectionArray(at section: Int, data: [Person]) -> [String] { let list = data.filter { - return StringManager.shared.chosungCheck(word: $0.familyName + $0.firstName) == sectionHeaderList.value[section-1] + return StringManager.shared.chosungCheck(word: $0.familyName + $0.firstName) == sectionHeaderList[section-1] }.map { person in return person.familyName + person.firstName } diff --git a/CheoMooRac/CheoMooRac/Sources/Views/MainTableViewController.swift b/CheoMooRac/CheoMooRac/Sources/Views/MainTableViewController.swift index 3d13df7..22855dc 100644 --- a/CheoMooRac/CheoMooRac/Sources/Views/MainTableViewController.swift +++ b/CheoMooRac/CheoMooRac/Sources/Views/MainTableViewController.swift @@ -69,7 +69,7 @@ extension MainTableViewController { extension MainTableViewController { override func numberOfSections(in tableView: UITableView) -> Int { - return viewModel.sectionHeaderList.value.count + 1 + return viewModel.sectionHeaderList.count + 1 } override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { @@ -94,7 +94,7 @@ extension MainTableViewController { guard let isFiltering = isFiltering else {return 1} return isFiltering ? 0 : 1 default: - return viewModel.getSectionArray(at: section).value.count + return viewModel.getSectionArray(at: section).count } } @@ -104,9 +104,9 @@ extension MainTableViewController { let cell = tableView.dequeueReusableCell(indexPath: indexPath) as MyCardTableViewCell return cell - case 1...viewModel.sectionHeaderList.value.count: + case 1...viewModel.sectionHeaderList.count: let cell = UITableViewCell() - cell.textLabel?.text = viewModel.getSectionArray(at: indexPath.section).value[indexPath.row] + cell.textLabel?.text = viewModel.getSectionArray(at: indexPath.section)[indexPath.row] return cell default: @@ -116,14 +116,14 @@ extension MainTableViewController { override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { if section != 0 { - return viewModel.sectionHeaderList.value[section - 1] + return viewModel.sectionHeaderList[section - 1] } else { return nil } } override func sectionIndexTitles(for tableView: UITableView) -> [String]? { - return viewModel.sectionHeaderList.value + return viewModel.sectionHeaderList } }