@@ -27,8 +27,6 @@ final class StopWatchViewController: UIViewController {
27
27
28
28
weak var delegate : StopWatchVCDelegate ?
29
29
30
- var saveDate : String = " "
31
-
32
30
private let guideLabelView = GuideLabelView ( )
33
31
private let calendarView = CalendarView ( )
34
32
private let goalTimeView = GoalTimeView ( )
@@ -92,13 +90,12 @@ final class StopWatchViewController: UIViewController {
92
90
// gesture
93
91
self . hideKeyboardWhenTapped ( )
94
92
95
- // print("path = \(Realm.Configuration.defaultConfiguration.fileURL!)")
93
+ // print("path = \(Realm.Configuration.defaultConfiguration.fileURL!)")
96
94
}
97
95
98
96
override func viewWillAppear( _ animated: Bool ) {
99
97
super. viewWillAppear ( animated)
100
98
// 프로퍼티 값 갱신
101
- self . saveDate = ( UIApplication . shared. delegate as! AppDelegate ) . resetDate //오늘 날짜!
102
99
103
100
self . setDeviceMotion ( ) // coremotion 시작
104
101
self . reloadProgressBar ( ) // 진행바 재로딩
@@ -122,7 +119,7 @@ final class StopWatchViewController: UIViewController {
122
119
123
120
//MARK: - Method
124
121
private func autoScrollCurrentDate( ) { // 현재 날짜로 달력 스크롤
125
- let itemIndex = CalendarMethod ( ) . returnIndexOfDay ( date: self . saveDate )
122
+ let itemIndex = CalendarMethod ( ) . returnIndexOfDay ( date: self . calendarView . selectDateComponent . stringFormat )
126
123
self . calendarView. calendarView. scrollToItem ( at: IndexPath ( item: itemIndex - 1 , section: 0 ) , at: . left, animated: true )
127
124
}
128
125
@@ -171,9 +168,9 @@ final class StopWatchViewController: UIViewController {
171
168
UIView . animate ( withDuration: 0.3 ) {
172
169
self . editGoalTimeView!. transform = . identity
173
170
}
174
- StopWatchDAO ( ) . create ( date: self . saveDate ) // 오늘 데이터가 없으면 데이터 생성
171
+ StopWatchDAO ( ) . create ( date: self . calendarView . selectDateComponent . stringFormat ) // 오늘 데이터가 없으면 데이터 생성
175
172
176
- let dailyData = self . realm. object ( ofType: DailyData . self, forPrimaryKey: self . saveDate ) !
173
+ let dailyData = self . realm. object ( ofType: DailyData . self, forPrimaryKey: self . calendarView . selectDateComponent . stringFormat ) !
177
174
let goal = dailyData. totalGoalTime
178
175
let hourIndex = Int ( goal / 3600 ) % 24 // 3600초 (1시간)으로 나눈 몫을 24로 나누면 시간 인덱스와 같다.
179
176
let miniuteIndex = ( ( Int ( goal) % 3600 ) / 60 ) / 5 // 남은 분을 5로 나누면 5분간격의 분 인덱스와 같다.
@@ -190,7 +187,7 @@ final class StopWatchViewController: UIViewController {
190
187
UIView . animate ( withDuration: 0.5 , animations: {
191
188
_editGoalTimeView. transform = CGAffineTransform ( translationX: 0 , y: self . view. frame. height)
192
189
} ) { _ in
193
- StopWatchDAO ( ) . deleteDailyData ( date: self . saveDate )
190
+ StopWatchDAO ( ) . deleteDailyData ( date: self . calendarView . selectDateComponent . stringFormat )
194
191
_editGoalTimeView. removeFromSuperview ( )
195
192
self . editGoalTimeView = nil
196
193
self . removeTapGesture ( )
@@ -225,7 +222,7 @@ final class StopWatchViewController: UIViewController {
225
222
if self . chartView != nil { return }
226
223
227
224
self . chartView = ChartView ( ) . then {
228
- $0. saveDate = self . saveDate
225
+ $0. saveDate = self . calendarView . selectDateComponent . stringFormat
229
226
230
227
self . frameView. addSubview ( $0)
231
228
$0. snp. makeConstraints { make in
@@ -338,15 +335,14 @@ final class StopWatchViewController: UIViewController {
338
335
339
336
@objc func didChangeSaveDate( _ notification: Notification ) {
340
337
if let saveDate = notification. userInfo ? [ " selectedDate " ] as? String {
341
- self . saveDate = saveDate
338
+ self . chartView ? . saveDate = saveDate
342
339
}
343
340
344
341
self . setGoalTime ( ) // 목표시간 Label 재설정
345
342
self . reloadProgressBar ( ) // 진행바 재로딩
346
343
self . setTimeLabel ( ) // 현재시간 Label 재설정
347
344
self . toDoTableView. reloadData ( )
348
345
self . calendarView. calendarView. reloadData ( )
349
- self . chartView? . saveDate = self . saveDate
350
346
self . chartView? . setNeedsDisplay ( ) // 차트 다시 그리기
351
347
}
352
348
@@ -361,7 +357,7 @@ final class StopWatchViewController: UIViewController {
361
357
// 목표 시간 설정 뷰 닫기
362
358
@objc func didFinishEditingGoalTime( _ sender: UIButton ) {
363
359
if sender. tag == 1 { // 확인버튼
364
- let dailyData = self . realm. object ( ofType: DailyData . self, forPrimaryKey: self . saveDate )
360
+ let dailyData = self . realm. object ( ofType: DailyData . self, forPrimaryKey: self . calendarView . selectDateComponent . stringFormat )
365
361
try ! self . realm. write {
366
362
dailyData!. totalGoalTime =
367
363
self . editGoalTimeView!. selectedHour + self . editGoalTimeView!. selectedMinute
@@ -391,9 +387,9 @@ final class StopWatchViewController: UIViewController {
391
387
392
388
//세션(과목명)을 눌렀을때 호출되는 메소드
393
389
@objc func didClickSection( _ sender: UIButton ) {
394
- StopWatchDAO ( ) . create ( date: self . saveDate ) // 오늘 데이터가 없으면 데이터 생성
390
+ StopWatchDAO ( ) . create ( date: self . calendarView . selectDateComponent . stringFormat ) // 오늘 데이터가 없으면 데이터 생성
395
391
396
- let dailyData = self . realm. object ( ofType: DailyData . self, forPrimaryKey: self . saveDate ) !
392
+ let dailyData = self . realm. object ( ofType: DailyData . self, forPrimaryKey: self . calendarView . selectDateComponent . stringFormat ) !
397
393
398
394
let segments = dailyData. dailySegment // 오늘 과목들
399
395
let section = sender. tag
@@ -622,9 +618,9 @@ extension StopWatchViewController: UITableViewDelegate,UITableViewDataSource{
622
618
}
623
619
624
620
func tableView( _ tableView: UITableView , numberOfRowsInSection section: Int ) -> Int {
625
- let filter = self . realm. object ( ofType: DailyData . self, forPrimaryKey: self . saveDate )
621
+ let filter = self . realm. object ( ofType: DailyData . self, forPrimaryKey: self . calendarView . selectDateComponent . stringFormat )
626
622
let segment = filter? . dailySegment
627
- StopWatchDAO ( ) . checkSegmentData ( date: self . saveDate )
623
+ StopWatchDAO ( ) . checkSegmentData ( date: self . calendarView . selectDateComponent . stringFormat )
628
624
return segment ? [ section] . toDoList. count ?? 0 // 오늘의 리스트가 없으면 0개
629
625
}
630
626
@@ -706,7 +702,7 @@ extension StopWatchViewController: UITableViewDelegate,UITableViewDataSource{
706
702
// 마지막 섹션에 문구 출력
707
703
if section == ( categoryCount - 1 ) {
708
704
// 오늘의 데이터가 nil일때
709
- guard let category = self . realm. object ( ofType: DailyData . self, forPrimaryKey: self . saveDate ) else { return guideText }
705
+ guard let category = self . realm. object ( ofType: DailyData . self, forPrimaryKey: self . calendarView . selectDateComponent . stringFormat ) else { return guideText }
710
706
711
707
var sum = 0 // todolist 합
712
708
@@ -726,7 +722,7 @@ extension StopWatchViewController: UITableViewDelegate,UITableViewDataSource{
726
722
extension StopWatchViewController : UITextFieldDelegate {
727
723
//입력이 끝나면 호출되는 델리게이트메소드
728
724
func textFieldDidEndEditing( _ textField: UITextField , reason: UITextField . DidEndEditingReason ) {
729
- let filter = self . realm. object ( ofType: DailyData . self, forPrimaryKey: self . saveDate )
725
+ let filter = self . realm. object ( ofType: DailyData . self, forPrimaryKey: self . calendarView . selectDateComponent . stringFormat )
730
726
let segment = filter!. dailySegment
731
727
732
728
let row = segment [ textField. tag] . toDoList. count - 1
@@ -736,7 +732,7 @@ extension StopWatchViewController: UITextFieldDelegate {
736
732
segment [ textField. tag] . toDoList. remove ( at: row)
737
733
segment [ textField. tag] . listCheckImageIndex. remove ( at: row)
738
734
}
739
- StopWatchDAO ( ) . deleteDailyData ( date: self . saveDate )
735
+ StopWatchDAO ( ) . deleteDailyData ( date: self . calendarView . selectDateComponent . stringFormat )
740
736
741
737
} else {
742
738
try ! self . realm. write {
@@ -754,7 +750,7 @@ extension StopWatchViewController: UITextFieldDelegate {
754
750
}
755
751
756
752
func textFieldDidChangeSelection( _ textField: UITextField ) {
757
- let filter = self . realm. object ( ofType: DailyData . self, forPrimaryKey: self . saveDate )
753
+ let filter = self . realm. object ( ofType: DailyData . self, forPrimaryKey: self . calendarView . selectDateComponent . stringFormat )
758
754
let segment = filter!. dailySegment
759
755
760
756
let row = segment [ textField. tag] . toDoList. count - 1
@@ -821,3 +817,4 @@ extension StopWatchViewController {
821
817
}
822
818
}
823
819
}
820
+
0 commit comments