@@ -8,7 +8,7 @@
9import UIKit
9import UIKit
11−class ClientsViewController: UITableViewController {
11+class ClientsViewController: BaseTableViewController {
13 // MARK: - Properties
13 // MARK: - Properties
@@ -27,7 +27,7 @@ class ClientsViewController: UITableViewController {
27 override func viewDidLoad() {
27 override func viewDidLoad() {
28 super.viewDidLoad()
28 super.viewDidLoad()
30− navigationItem.title = "Клиенты"
30+ setupNavigationBar()
31 clientsService = ClientsService(apiClient: APIClient.shared)
31 clientsService = ClientsService(apiClient: APIClient.shared)
@@ -40,6 +40,16 @@ class ClientsViewController: UITableViewController {
40 super.viewDidAppear(animated)
40 super.viewDidAppear(animated)
41 loadClients()
41 loadClients()
46+ func setupNavigationBar() {
48+ navigationItem.title = "Клиенты"
49+ navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .action, target: self, action: #selector(shareCSVFile))
44 /// Загружаем клиентов кальянки
54 /// Загружаем клиентов кальянки
45 func loadClients() {
55 func loadClients() {
@@ -53,8 +63,39 @@ class ClientsViewController: UITableViewController {
66+ // MARK: - Button handlers
68+ /// https://developer.apple.com/design/human-interface-guidelines/ios/views/activity-views/
69+ @objc func shareCSVFile() {
71+ let str = HFunc.main.exportClientsToCSV(dataSource)
72+ let filename = getDocumentsDirectory().appendingPathComponent("clients.csv")
75+ try str.write(toFile: filename, atomically: true, encoding: String.Encoding.utf8)
77+ let fileData = NSURL(fileURLWithPath: filename)
79+ let objectsToShare = [fileData]
80+ let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
82+ self.present(activityVC, animated: true, completion: nil)
85+ self.displayAlert(with: "По какой-то причине не могу сохранить файл!")
89+ func getDocumentsDirectory() -> NSString {
90+ let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
91+ let documentsDirectory = paths[0]
92+ return documentsDirectory as NSString
57− // MARK: - Tableview
96+// MARK: - Tableview
98+extension ClientsViewController {
59 override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
100 override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
60 let cell = tableView.dequeueReusableCell(withIdentifier: clientTableViewCellId, for: indexPath) as! ClientTableViewCell
101 let cell = tableView.dequeueReusableCell(withIdentifier: clientTableViewCellId, for: indexPath) as! ClientTableViewCell