Initial Project Commit

This commit is contained in:
Garth Vander Houwen 2021-08-20 07:56:05 -07:00
parent ff017aab5e
commit 8be3ac2bba
23 changed files with 898 additions and 166 deletions

View file

@ -0,0 +1,37 @@
/*
See LICENSE folder for this apps licensing information.
Abstract:
A representation of a single device.
*/
import Foundation
import SwiftUI
import CoreLocation
struct Device: Hashable, Codable, Identifiable {
var longName: String
var shortName: String
var id: String
var region: String
var hasGPS: Bool
var isRouter: Bool
var firmwareVersion: String
var hardwareModel: String
var lastHeard: Double
var snr: Double
private var imageName: String
var image: Image {
Image(imageName)
}
var position: Position
struct Position: Hashable, Codable {
var latitude: Double
var longitude: Double
var altitude: Int
var batteryLevel: Int }
}

View file

@ -0,0 +1,37 @@
/*
Abstract:
Storage for model data.
*/
import Foundation
import Combine
final class ModelData: ObservableObject {
@Published var devices: [Device] = load("deviceData.json")
var nearby: [Device] {
devices
}
}
func load<T: Decodable>(_ filename: String) -> T {
let data: Data
guard let file = Bundle.main.url(forResource: filename, withExtension: nil)
else {
fatalError("Couldn't find \(filename) in main bundle.")
}
do {
data = try Data(contentsOf: file)
} catch {
fatalError("Couldn't load \(filename) from main bundle:\n\(error)")
}
do {
let decoder = JSONDecoder()
return try decoder.decode(T.self, from: data)
} catch {
fatalError("Couldn't parse \(filename) as \(T.self):\n\(error)")
}
}