-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathViewController.swift
37 lines (24 loc) · 1.08 KB
/
ViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var dateTF: UITextField!
@IBOutlet weak var monthTF: UITextField!
@IBOutlet weak var yearTF: UITextField!
@IBOutlet weak var resultLabel: UILabel!
@IBAction func findDateButton(_ sender: UIButton) {
guard let day = dateTF.text, let month = monthTF.text, let year = yearTF.text else { return }
let calendar = Calendar.current
var dateComponets = DateComponents()
dateComponets.day = Int(day)
dateComponets.month = Int(month)
dateComponets.year = Int(year)
let dateFormator = DateFormatter()
dateFormator.dateFormat = "EEEE"
guard let date = calendar.date(from: dateComponets) else { return }
let weekday = dateFormator.string(from: date)
let capitalizedWeekday = weekday.capitalized
resultLabel.text = capitalizedWeekday
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
self.view.endEditing(true)
}
}