2 // ResourceHistoryDataStore.swift
5 // Created by Hori,Masaki on 2017/01/06.
6 // Copyright © 2017年 Hori,Masaki. All rights reserved.
11 extension CoreDataConfiguration {
12 static let resourceHistory = CoreDataConfiguration("ResourceHistory")
14 extension CoreDataCore {
15 static let resourceHistory = CoreDataCore(.resourceHistory)
18 class ResourceHistoryDataStore: CoreDataAccessor, CoreDataManager {
19 static var `default` = ResourceHistoryDataStore(type: .reader)
20 class func oneTimeEditor() -> ResourceHistoryDataStore {
21 return ResourceHistoryDataStore(type: .editor)
24 required init(type: CoreDataManagerType) {
25 context = (type == .reader ? core.parentContext : core.editorContext())
31 let core = CoreDataCore.resourceHistory
32 let context: NSManagedObjectContext
35 extension ResourceHistoryDataStore {
36 func resources(in minites: [Int], older: Date) -> [Resource] {
37 let p = NSPredicate(format: "minute IN %@ AND date < %@", minites, older as NSDate)
38 guard let resources = try? objects(with: Resource.entity, predicate: p)
42 func cerateResource() -> Resource? {
43 return insertNewObject(for: Resource.entity)