Skip to content

Commit

Permalink
⚡️ :: SDTimePicker 터지는 에러 고침
Browse files Browse the repository at this point in the history
  • Loading branch information
rlarldud1234 committed Mar 5, 2023
1 parent 8cb3985 commit 7024b0c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
16 changes: 7 additions & 9 deletions SemicolonDesign/Sources/TimePicker/SDTimePickerCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
)
}

Expand All @@ -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
)
Expand Down

0 comments on commit 7024b0c

Please sign in to comment.