mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
61 lines
1.4 KiB
Swift
61 lines
1.4 KiB
Swift
//
|
|
// UpdateCoreData.swift
|
|
// Meshtastic
|
|
//
|
|
// Copyright(c) Garth Vander Houwen 10/3/22.
|
|
|
|
import CoreData
|
|
|
|
public func clearPositions(destNum: Int64, context: NSManagedObjectContext) -> Bool {
|
|
|
|
let fetchNodeInfoRequest: NSFetchRequest<NSFetchRequestResult> = NSFetchRequest.init(entityName: "NodeInfoEntity")
|
|
fetchNodeInfoRequest.predicate = NSPredicate(format: "num == %lld", Int64(destNum))
|
|
|
|
do {
|
|
|
|
let fetchedNode = try context.fetch(fetchNodeInfoRequest) as! [NodeInfoEntity]
|
|
|
|
let newPostions = [PositionEntity]()
|
|
fetchedNode[0].positions? = NSOrderedSet(array: newPostions)
|
|
|
|
do {
|
|
try context.save()
|
|
return true
|
|
|
|
} catch {
|
|
context.rollback()
|
|
return false
|
|
}
|
|
|
|
} catch {
|
|
print("💥 Fetch NodeInfoEntity Error")
|
|
return false
|
|
}
|
|
}
|
|
|
|
public func clearTelemetry(destNum: Int64, metricsType: Int32, context: NSManagedObjectContext) -> Bool {
|
|
|
|
let fetchNodeInfoRequest: NSFetchRequest<NSFetchRequestResult> = NSFetchRequest.init(entityName: "NodeInfoEntity")
|
|
fetchNodeInfoRequest.predicate = NSPredicate(format: "num == %lld", Int64(destNum))
|
|
|
|
do {
|
|
|
|
let fetchedNode = try context.fetch(fetchNodeInfoRequest) as! [NodeInfoEntity]
|
|
|
|
let emptyTelemetry = [TelemetryEntity]()
|
|
fetchedNode[0].telemetries? = NSOrderedSet(array: emptyTelemetry)
|
|
|
|
do {
|
|
try context.save()
|
|
return true
|
|
|
|
} catch {
|
|
context.rollback()
|
|
return false
|
|
}
|
|
|
|
} catch {
|
|
print("💥 Fetch NodeInfoEntity Error")
|
|
return false
|
|
}
|
|
}
|