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 )