diff --git a/GeofenceTester.xcodeproj/project.pbxproj b/GeofenceTester.xcodeproj/project.pbxproj index 1144c9a..b158d03 100644 --- a/GeofenceTester.xcodeproj/project.pbxproj +++ b/GeofenceTester.xcodeproj/project.pbxproj @@ -17,6 +17,7 @@ CB655F7E2856A43B00EBCABA /* RegionsListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB655F7D2856A43B00EBCABA /* RegionsListViewController.swift */; }; CBE711EF2868EE36008F51C4 /* RegionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CBE711EE2868EE36008F51C4 /* RegionViewController.swift */; }; CBE711F1286915A8008F51C4 /* EventRecord.swift in Sources */ = {isa = PBXBuildFile; fileRef = CBE711F0286915A8008F51C4 /* EventRecord.swift */; }; + CBE711F3286920FD008F51C4 /* EventsTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CBE711F2286920FD008F51C4 /* EventsTableViewController.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -32,6 +33,7 @@ CB655F7D2856A43B00EBCABA /* RegionsListViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegionsListViewController.swift; sourceTree = ""; }; CBE711EE2868EE36008F51C4 /* RegionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegionViewController.swift; sourceTree = ""; }; CBE711F0286915A8008F51C4 /* EventRecord.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventRecord.swift; sourceTree = ""; }; + CBE711F2286920FD008F51C4 /* EventsTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventsTableViewController.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -69,6 +71,7 @@ CB655F6928534E2600EBCABA /* ViewController.swift */, CB655F7D2856A43B00EBCABA /* RegionsListViewController.swift */, CBE711EE2868EE36008F51C4 /* RegionViewController.swift */, + CBE711F2286920FD008F51C4 /* EventsTableViewController.swift */, CBE711F0286915A8008F51C4 /* EventRecord.swift */, CB268B9F285A19DC00B16C3A /* PersistantStorage.swift */, CB655F6B28534E2600EBCABA /* Main.storyboard */, @@ -156,6 +159,7 @@ CBE711EF2868EE36008F51C4 /* RegionViewController.swift in Sources */, CB655F6828534E2600EBCABA /* SceneDelegate.swift in Sources */, CB655F7E2856A43B00EBCABA /* RegionsListViewController.swift in Sources */, + CBE711F3286920FD008F51C4 /* EventsTableViewController.swift in Sources */, CB268BA0285A19DC00B16C3A /* PersistantStorage.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/GeofenceTester/Base.lproj/Main.storyboard b/GeofenceTester/Base.lproj/Main.storyboard index faac25c..dd80962 100644 --- a/GeofenceTester/Base.lproj/Main.storyboard +++ b/GeofenceTester/Base.lproj/Main.storyboard @@ -149,7 +149,11 @@ - + + + + + @@ -166,6 +170,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/GeofenceTester/EventsTableViewController.swift b/GeofenceTester/EventsTableViewController.swift new file mode 100644 index 0000000..d7c35a7 --- /dev/null +++ b/GeofenceTester/EventsTableViewController.swift @@ -0,0 +1,85 @@ +// +// EventsTableViewController.swift +// GeofenceTester +// +// Created by Alexander von Below on 27.06.22. +// + +import UIKit + +class EventsTableViewController: UITableViewController { + + var storage: PersistantStorage! + + override func viewDidLoad() { + super.viewDidLoad() + + self.title = "Events" + // Uncomment the following line to preserve selection between presentations + // self.clearsSelectionOnViewWillAppear = false + + // Uncomment the following line to display an Edit button in the navigation bar for this view controller. + // self.navigationItem.rightBarButtonItem = self.editButtonItem + self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "Event Cell") + } + + @IBAction func share() { + let text = storage.storage.reduce("") { partialResult, event in + partialResult + event.debugDescription + "\n" + } + let activityController = UIActivityViewController(activityItems: [text], applicationActivities: nil) + self.present(activityController, animated: true) + } + + // MARK: - Table view data source + + override func numberOfSections(in tableView: UITableView) -> Int { + return 1 + } + + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return storage.storage.count + } + + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell = tableView.dequeueReusableCell(withIdentifier: "Event Cell", for: indexPath) + + var config = cell.defaultContentConfiguration() + let event = storage.storage[indexPath.row] + config.text = event.debugDescription + cell.contentConfiguration = config + return cell + } + + /* + // Override to support conditional editing of the table view. + override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { + // Return false if you do not want the specified item to be editable. + return true + } + */ + + /* + // Override to support editing the table view. + override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) { + if editingStyle == .delete { + // Delete the row from the data source + tableView.deleteRows(at: [indexPath], with: .fade) + } else if editingStyle == .insert { + // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view + } + } + */ + + + /* + // MARK: - Navigation + + // In a storyboard-based application, you will often want to do a little preparation before navigation + override func prepare(for segue: UIStoryboardSegue, sender: Any?) { + // Get the new view controller using segue.destination. + // Pass the selected object to the new view controller. + } + */ + +} diff --git a/GeofenceTester/PersistantStorage.swift b/GeofenceTester/PersistantStorage.swift index 554a13b..b242bea 100644 --- a/GeofenceTester/PersistantStorage.swift +++ b/GeofenceTester/PersistantStorage.swift @@ -11,7 +11,7 @@ import Foundation class PersistantStorage { - private var storage = Array() + public private(set) var storage = Array() private let decoder = JSONDecoder() private let encoder = JSONEncoder() private let kFilename = "geolocator.log" diff --git a/GeofenceTester/RegionsListViewController.swift b/GeofenceTester/RegionsListViewController.swift index 41b5db0..dab8ca8 100644 --- a/GeofenceTester/RegionsListViewController.swift +++ b/GeofenceTester/RegionsListViewController.swift @@ -12,6 +12,7 @@ import os.log class RegionsListViewController: UIViewController, MKMapViewDelegate { var locationManager: CLLocationManager! + var storage: PersistantStorage! private var logger = Logger() @IBOutlet var mapView: MKMapView! @@ -123,7 +124,7 @@ class RegionsListViewController: UIViewController, MKMapViewDelegate { // In a storyboard-based application, you will often want to do a little preparation before navigation override func prepare(for segue: UIStoryboardSegue, sender: Any?) { - if let detailView = segue.destination as? RegionViewController { + if let destination = segue.destination as? RegionViewController { guard let annotation = sender as? MKAnnotation else { let logger = Logger() logger.log(level: .error, "Sender was not MKAnnotation") @@ -132,8 +133,12 @@ class RegionsListViewController: UIViewController, MKMapViewDelegate { guard let identifier = annotation.title else { return } - detailView.identifier = identifier - detailView.locationManager = locationManager + destination.identifier = identifier + destination.locationManager = locationManager + } + + if let destination = segue.destination as? EventsTableViewController { + destination.storage = storage } } diff --git a/GeofenceTester/ViewController.swift b/GeofenceTester/ViewController.swift index f2b60e1..95c28b5 100644 --- a/GeofenceTester/ViewController.swift +++ b/GeofenceTester/ViewController.swift @@ -171,6 +171,7 @@ class ViewController: UIViewController, CLLocationManagerDelegate { override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if let regionsController = segue.destination as? RegionsListViewController { regionsController.locationManager = locationManager + regionsController.storage = storage } } }