-
-
Notifications
You must be signed in to change notification settings - Fork 726
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use same calculator on Watch as on iPhone app.
- Loading branch information
Showing
10 changed files
with
137 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import CoreData | ||
import Foundation | ||
import SwiftDate | ||
import Swinject | ||
|
||
final class CoreDataStorage { | ||
let coredataContext = CoreDataStack.shared.persistentContainer.viewContext // newBackgroundContext() | ||
|
||
func fetchGlucose(interval: NSDate) -> [Readings] { | ||
var fetchGlucose = [Readings]() | ||
coredataContext.performAndWait { | ||
let requestReadings = Readings.fetchRequest() as NSFetchRequest<Readings> | ||
let sort = NSSortDescriptor(key: "date", ascending: false) | ||
requestReadings.sortDescriptors = [sort] | ||
requestReadings.predicate = NSPredicate( | ||
format: "glucose > 0 AND date > %@", interval | ||
) | ||
try? fetchGlucose = self.coredataContext.fetch(requestReadings) | ||
} | ||
return fetchGlucose | ||
} | ||
|
||
func fetchLatestOverride() -> [Override] { | ||
var overrideArray = [Override]() | ||
coredataContext.performAndWait { | ||
let requestOverrides = Override.fetchRequest() as NSFetchRequest<Override> | ||
let sortOverride = NSSortDescriptor(key: "date", ascending: false) | ||
requestOverrides.sortDescriptors = [sortOverride] | ||
requestOverrides.fetchLimit = 1 | ||
try? overrideArray = self.coredataContext.fetch(requestOverrides) | ||
} | ||
return overrideArray | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters