This repository was archived by the owner on Oct 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDupeViewController.swift
More file actions
60 lines (43 loc) · 1.51 KB
/
DupeViewController.swift
File metadata and controls
60 lines (43 loc) · 1.51 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import InterfaceBacked
import UIKit
protocol DupeViewDelegate: class {
func controllerDidCancel(_ controller: DupeViewController)
func controller(_ controller: DupeViewController, didSubmit number: String)
}
final class DupeViewController: UIViewController, StoryboardBacked, StatusDisplay {
// MARK: - Properties
@IBOutlet private weak var numberField: UITextField!
@IBOutlet private weak var hintLabel: UILabel!
var number: String = ""
weak var delegate: DupeViewDelegate?
// MARK: - UIViewController Methods
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if let content = UIPasteboard.general.string, content.isOpenRadar && number.isEmpty {
numberField.text = content.extractRadarNumber()
hintLabel.text = "Found \(content) on your clipboard"
} else {
hintLabel.text = "You can also post rdar:// or https://openradar.appspot.com/ links"
}
if number.isNotEmpty && number.isOpenRadar {
numberField.text = number
}
}
// MARK: - User Actions
@IBAction func submitTapped() {
// TODO: Show error if invalid
guard let text = numberField.text, text.isOpenRadar else { return }
let number = text.extractRadarNumber() ?? ""
delegate?.controller(self, didSubmit: number)
}
@IBAction func cancelTapped() {
delegate?.controllerDidCancel(self)
}
}
// MARK: - UITextFieldDelegate Methods
extension DupeViewController: UITextFieldDelegate {
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}
}