-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathItem+CoreDataClass.swift
42 lines (40 loc) · 1.04 KB
/
Item+CoreDataClass.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//
// Item+CoreDataClass.swift
// Permit Tracker
//
// Created by Everett Wilber on 2/6/22.
//
//
import Foundation
import CoreData
import CoreLocation
import Accelerate
@objc(Item)
public class Item: NSManagedObject {
public func update() {
GetDriveDistance()
}
public func GetDriveDistance() -> (Measurement<UnitLength>, Double) {
if distance == 0.0 {
var totalDistance: Double = 0
if var lastLocation = self.locations?.firstObject as? LocationEntity {
for location in self.locations!.array as! [LocationEntity] {
let dist = location.distance(from: lastLocation)
if dist > sqrt(pow(location.verticalAccuracy, 2) + pow(location.horizontalAccuracy, 2)) {
totalDistance += dist
lastLocation = location
}
}
}
// print("in ns, totalDist =",totalDistance)
self.distance = totalDistance
} else {
// print("in ns, dist =",self.distance)
}
if distance == 0.0 {
print("0.0")
self.managedObjectContext?.delete(self)
}
return (Measurement(value: distance, unit: UnitLength.meters), distance)
}
}