From 7024b0cd4c63400f9277ae85d6e8fd8e904b7811 Mon Sep 17 00:00:00 2001 From: rlarldud1234 Date: Sun, 5 Mar 2023 18:51:19 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20::=20SDTimePicker=20?= =?UTF-8?q?=ED=84=B0=EC=A7=80=EB=8A=94=20=EC=97=90=EB=9F=AC=20=EA=B3=A0?= =?UTF-8?q?=EC=B9=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TimePicker/SDTimePickerCoordinator.swift | 16 +++++++--------- .../TimePicker/SDTimePickerRepresentable.swift | 9 +++++---- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/SemicolonDesign/Sources/TimePicker/SDTimePickerCoordinator.swift b/SemicolonDesign/Sources/TimePicker/SDTimePickerCoordinator.swift index 0911b93f..d5c50267 100644 --- a/SemicolonDesign/Sources/TimePicker/SDTimePickerCoordinator.swift +++ b/SemicolonDesign/Sources/TimePicker/SDTimePickerCoordinator.swift @@ -3,13 +3,13 @@ import UIKit class SDTimePickerCoordinator: NSObject, UIPickerViewDelegate, UIPickerViewDataSource { private let parent: SDTimePickerRepresentable - let hour: [Int] - let minute: [Int] + let hour: [String] + let minute: [String] init( _ parent: SDTimePickerRepresentable, - hour: [Int], - minute:[Int] + hour: [String], + minute:[String] ) { self.parent = parent self.hour = hour @@ -69,12 +69,10 @@ class SDTimePickerCoordinator: NSObject, UIPickerViewDelegate, UIPickerViewDataS func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) { switch component { case 0: - parent.hour = hour[row % hour.count] - pickerView.reloadComponent(2) + parent.hour = Int(hour[row % hour.count]) ?? 0 default: - parent.minute = minute[row % minute.count] - pickerView.reloadComponent(2) + parent.minute = Int(minute[row % minute.count]) ?? 0 } - self.parent.date = "\(parent.hour):\(parent.minute)".toDate("hh:mm") + self.parent.date = "\(parent.hour):\(parent.minute)".toDate("HH:mm") } } diff --git a/SemicolonDesign/Sources/TimePicker/SDTimePickerRepresentable.swift b/SemicolonDesign/Sources/TimePicker/SDTimePickerRepresentable.swift index 3a3f326b..79191ef3 100644 --- a/SemicolonDesign/Sources/TimePicker/SDTimePickerRepresentable.swift +++ b/SemicolonDesign/Sources/TimePicker/SDTimePickerRepresentable.swift @@ -10,8 +10,9 @@ struct SDTimePickerRepresentable: UIViewRepresentable { func makeCoordinator() -> SDTimePickerCoordinator { return SDTimePickerCoordinator( self, - hour: Array(0...23), - minute: [0, 10, 20, 30, 40, 50] + hour: ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", + "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23"], + minute: ["00", "10", "20", "30", "40", "50"] ) } @@ -24,12 +25,12 @@ struct SDTimePickerRepresentable: UIViewRepresentable { let minute = context.coordinator.minute pickerView.selectRow( - hour.firstIndex(of: self.hour)! + (hour.count * 5), + hour.firstIndex(of: String(self.hour))! + (hour.count * 5), inComponent: 0, animated: false ) pickerView.selectRow( - minute.firstIndex { $0 >= self.minute }! + (minute.count * 5), + minute.firstIndex { Int($0)! >= self.minute }! + (minute.count * 5), inComponent: 1, animated: false )