Move the destination data model stuff out of the UI.

This commit is contained in:
Jeremy Rand
2021-11-03 22:55:00 -04:00
parent 2c58886439
commit 0528a7db41
4 changed files with 28 additions and 12 deletions
+1 -1
View File
@@ -110,7 +110,6 @@
9D5155E626A1EF7B0075EBC7 = {
isa = PBXGroup;
children = (
9DD67CEF2728F5B700243FC6 /* DestinationsView.swift */,
9D51562126A1F0DF0075EBC7 /* LICENSE */,
9D51562A26A1F1B40075EBC7 /* README.md */,
9D5155F126A1EF7B0075EBC7 /* ListenerGS */,
@@ -137,6 +136,7 @@
9D0DC15826F2E47A007EB92D /* ListenerGS.entitlements */,
9D5155F226A1EF7B0075EBC7 /* ListenerGSApp.swift */,
9D6F27082728EF410089585E /* MainView.swift */,
9DD67CEF2728F5B700243FC6 /* DestinationsView.swift */,
9DCCDACB271FB87100F311DF /* GSDestinations.swift */,
9D5155F426A1EF7B0075EBC7 /* ContentView.swift */,
9D6ED239271E6BD600D773CD /* SpeechForwarder.swift */,
@@ -7,20 +7,17 @@
import SwiftUI
struct Destination: Identifiable, Hashable {
let ipAddress : String
let id = UUID()
}
struct DestinationsView: View {
@State private var destinations:[Destination] = []
@State private var editMode = EditMode.inactive
@State private var showPopover = false
@State private var newDestination = ""
@StateObject private var destinations = GSDestinations()
var body: some View {
List {
ForEach(destinations) { destination in
ForEach(destinations.dests) { destination in
NavigationLink(destination: Text(destination.ipAddress)) {
Text(destination.ipAddress)
}
@@ -70,11 +67,11 @@ struct DestinationsView: View {
}
private func onDelete(offsets: IndexSet) {
destinations.remove(atOffsets: offsets)
destinations.onDelete(offsets: offsets)
}
private func onMove(source: IndexSet, destination: Int) {
destinations.move(fromOffsets: source, toOffset: destination)
destinations.onMove(source: source, destination: destination)
}
func showAdd() {
@@ -82,7 +79,7 @@ struct DestinationsView: View {
}
func onAdd() {
destinations.append(Destination(ipAddress: self.newDestination))
destinations.onAdd(ipAddress: self.newDestination)
newDestination = ""
showPopover = false;
}
+20 -1
View File
@@ -7,5 +7,24 @@
import Foundation
class GSDestinations : ObservableObject {
struct Destination: Identifiable, Hashable {
let ipAddress : String
let id = UUID()
}
class GSDestinations : ObservableObject {
@Published var dests:[Destination] = []
public func onDelete(offsets: IndexSet) {
dests.remove(atOffsets: offsets)
}
public func onMove(source: IndexSet, destination: Int) {
dests.move(fromOffsets: source, toOffset: destination)
}
public func onAdd(ipAddress: String) {
dests.append(Destination(ipAddress: ipAddress))
}
}
+1 -1
View File
@@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>239</string>
<string>242</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSRequiresIPhoneOS</key>