@@ -8,7 +8,7 @@
88
99import UIKit
1010
11−class ClientsViewController: UITableViewController {
11+class ClientsViewController: BaseTableViewController {
1212
1313 // MARK: - Properties
1414
@@ -27,7 +27,7 @@ class ClientsViewController: UITableViewController {
2727 override func viewDidLoad() {
2828 super.viewDidLoad()
2929
30− navigationItem.title = "Клиенты"
30+ setupNavigationBar()
3131 clientsService = ClientsService(apiClient: APIClient.shared)
3232 }
3333
@@ -40,6 +40,16 @@ class ClientsViewController: UITableViewController {
4040 super.viewDidAppear(animated)
4141 loadClients()
4242 }
43+
44+ // MARK: - Setup
45+
46+ func setupNavigationBar() {
47+
48+ navigationItem.title = "Клиенты"
49+ navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .action, target: self, action: #selector(shareCSVFile))
50+ }
51+
52+ // MARK: - Api calls
4353
4454 /// Загружаем клиентов кальянки
4555 func loadClients() {
@@ -53,8 +63,39 @@ class ClientsViewController: UITableViewController {
5363 })
5464 }
5565
66+ // MARK: - Button handlers
5667
57− // MARK: - Tableview
68+ /// https://developer.apple.com/design/human-interface-guidelines/ios/views/activity-views/
69+ @objc func shareCSVFile() {
70+ //Your CSV text
71+ let str = HFunc.main.exportClientsToCSV(dataSource)
72+ let filename = getDocumentsDirectory().appendingPathComponent("clients.csv")
73+
74+ do {
75+ try str.write(toFile: filename, atomically: true, encoding: String.Encoding.utf8)
76+
77+ let fileData = NSURL(fileURLWithPath: filename)
78+
79+ let objectsToShare = [fileData]
80+ let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
81+
82+ self.present(activityVC, animated: true, completion: nil)
83+
84+ } catch {
85+ self.displayAlert(with: "По какой-то причине не могу сохранить файл!")
86+ }
87+ }
88+
89+ func getDocumentsDirectory() -> NSString {
90+ let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
91+ let documentsDirectory = paths[0]
92+ return documentsDirectory as NSString
93+ }
94+}
95+
96+// MARK: - Tableview
97+
98+extension ClientsViewController {
5899
59100 override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
60101 let cell = tableView.dequeueReusableCell(withIdentifier: clientTableViewCellId, for: indexPath) as! ClientTableViewCell