mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
initial swift data conversion
This commit is contained in:
parent
183924d4dc
commit
b2c72ae166
130 changed files with 2939 additions and 2269 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue