initial swift data conversion

This commit is contained in:
Garth Vander Houwen 2026-04-16 12:10:00 -07:00
parent 183924d4dc
commit b2c72ae166
130 changed files with 2939 additions and 2269 deletions

View file

@ -29,8 +29,9 @@ struct FactoryResetNodeIntent: AppIntent {
}
// Safely unwrap the connected node information
let context = await MainActor.run { PersistenceController.shared.context }
if let connectedPeripheralNum = await AccessoryManager.shared.activeDeviceNum,
let connectedNode = getNodeInfo(id: connectedPeripheralNum, context: PersistenceController.shared.container.viewContext),
let connectedNode = getNodeInfo(id: connectedPeripheralNum, context: context),
let fromUser = connectedNode.user,
let toUser = connectedNode.user {

View file

@ -8,7 +8,7 @@
import Foundation
import AppIntents
import CoreLocation
import CoreData
import SwiftData
import UIKit
@available(iOS 16.4, *)
@ -26,12 +26,15 @@ struct NavigateToNodeIntent: ForegroundContinuableIntent {
throw AppIntentErrors.AppIntentError.notConnected
}
let fetchNodeInfoRequest: NSFetchRequest<NSFetchRequestResult> = NSFetchRequest(entityName: "NodeInfoEntity")
fetchNodeInfoRequest.predicate = NSPredicate(format: "num == %lld", Int64(nodeNum))
let nodeNumInt64 = Int64(nodeNum)
var descriptor = FetchDescriptor<NodeInfoEntity>(
predicate: #Predicate<NodeInfoEntity> { $0.num == nodeNumInt64 }
)
descriptor.fetchLimit = 1
do {
guard let fetchedNode = try PersistenceController.shared.container.viewContext.fetch(fetchNodeInfoRequest) as? [NodeInfoEntity],
fetchedNode.count == 1 else {
let fetchedNode = try await MainActor.run { try PersistenceController.shared.context.fetch(descriptor) }
guard fetchedNode.count == 1 else {
throw $nodeNum.needsValueError("Could not find node")
}

View file

@ -8,7 +8,7 @@
import Foundation
import AppIntents
import CoreLocation
import CoreData
import SwiftData
struct NodePositionIntent: AppIntent {
@ -22,16 +22,19 @@ struct NodePositionIntent: AppIntent {
if !(await AccessoryManager.shared.isConnected) {
throw AppIntentErrors.AppIntentError.notConnected
}
let fetchNodeInfoRequest: NSFetchRequest<NSFetchRequestResult> = NSFetchRequest(entityName: "NodeInfoEntity")
fetchNodeInfoRequest.predicate = NSPredicate(format: "num == %lld", Int64(nodeNum))
let nodeNumInt64 = Int64(nodeNum)
var descriptor = FetchDescriptor<NodeInfoEntity>(
predicate: #Predicate<NodeInfoEntity> { $0.num == nodeNumInt64 }
)
descriptor.fetchLimit = 1
do {
guard let fetchedNode = try PersistenceController.shared.container.viewContext.fetch(fetchNodeInfoRequest) as? [NodeInfoEntity], fetchedNode.count == 1 else {
let fetchedNode = try await MainActor.run { try PersistenceController.shared.context.fetch(descriptor) }
guard fetchedNode.count == 1 else {
throw $nodeNum.needsValueError("Could not find node")
}
let nodeInfo = fetchedNode[0]
if let latitude = nodeInfo.latestPosition?.coordinate.latitude,
let longitude = nodeInfo.latestPosition?.coordinate.longitude {
let nodeLocation = CLLocation(latitude: latitude, longitude: longitude)
if let coord = nodeInfo.latestPosition?.nodeCoordinate {
let nodeLocation = CLLocation(latitude: coord.latitude, longitude: coord.longitude)
// Reverse geocode the CLLocation to get a CLPlacemark
let geocoder = CLGeocoder()
let placemarks = try await geocoder.reverseGeocodeLocation(nodeLocation)

View file

@ -19,8 +19,9 @@ struct RestartNodeIntent: AppIntent {
throw AppIntentErrors.AppIntentError.notConnected
}
// Safely unwrap the connectedNode using if let
let context = await MainActor.run { PersistenceController.shared.context }
if let connectedPeripheralNum = await AccessoryManager.shared.activeDeviceNum,
let connectedNode = getNodeInfo(id: connectedPeripheralNum, context: PersistenceController.shared.container.viewContext),
let connectedNode = getNodeInfo(id: connectedPeripheralNum, context: context),
let fromUser = connectedNode.user,
let toUser = connectedNode.user {

View file

@ -21,8 +21,9 @@ struct ShutDownNodeIntent: AppIntent {
}
// Safely unwrap the connectedNode using if let
let context = await MainActor.run { PersistenceController.shared.context }
if let connectedPeripheralNum = await AccessoryManager.shared.activeDeviceNum,
let connectedNode = getNodeInfo(id: connectedPeripheralNum, context: PersistenceController.shared.container.viewContext),
let connectedNode = getNodeInfo(id: connectedPeripheralNum, context: context),
let fromUser = connectedNode.user,
let toUser = connectedNode.user {