Forecast+helper.swift 579 B

1234567891011121314151617
  1. import CoreData
  2. import Foundation
  3. public extension Forecast {
  4. static func fetch(_ predicate: NSPredicate, sortedBy keyPath: String, ascending: Bool) -> NSFetchRequest<Forecast> {
  5. let request = NSFetchRequest<Forecast>(entityName: "Forecast")
  6. request.sortDescriptors = [NSSortDescriptor(key: keyPath, ascending: ascending)]
  7. request.predicate = predicate
  8. return request
  9. }
  10. var forecastValuesArray: [ForecastValue] {
  11. let set = forecastValues as? Set<ForecastValue> ?? []
  12. return set.sorted { $0.index < $1.index }
  13. }
  14. }