2 // ResourceHistoryDataStore.swift
5 // Created by Hori,Masaki on 2017/01/06.
6 // Copyright © 2017年 Hori,Masaki. All rights reserved.
11 extension CoreDataConfiguration {
13 static let resourceHistory = CoreDataConfiguration("ResourceHistory")
16 final class ResourceHistoryDataStore: CoreDataAccessor, CoreDataManager {
18 static let core = CoreDataCore(.resourceHistory)
20 static let `default` = ResourceHistoryDataStore(type: .reader)
22 class func oneTimeEditor() -> ResourceHistoryDataStore {
24 return ResourceHistoryDataStore(type: .editor)
27 required init(type: CoreDataManagerType) {
29 context = ResourceHistoryDataStore.context(for: type)
37 let context: NSManagedObjectContext
40 extension ResourceHistoryDataStore {
42 func resources(in minites: [Int], older: Date) -> [Resource] {
44 let p = NSPredicate.empty
45 .and(NSPredicate(#keyPath(Resource.minute), valuesIn: minites))
46 .and(NSPredicate(#keyPath(Resource.date), lessThan: older))
48 guard let resources = try? objects(of: Resource.entity, predicate: p) else { return [] }
53 func createResource() -> Resource? {
55 return insertNewObject(for: Resource.entity)