OSDN Git Service

staticプロパティをインスタンスプロパティに変更
[kcd/KCD.git] / KCD / ResourceHistoryDataStore.swift
index 29e2c6a..afbd510 100644 (file)
@@ -7,37 +7,23 @@
 //
 
 import Cocoa
+import Doutaku
 
-extension CoreDataConfiguration {
-    static let resourceHistory = CoreDataConfiguration("ResourceHistory")
-}
-
-class ResourceHistoryDataStore: CoreDataAccessor, CoreDataManager {
-    static let core = CoreDataCore(.resourceHistory)
+final class ResourceHistoryDataStore: CoreDataManager {
+    
+    static let core = CoreDataCore(CoreDataConfiguration("ResourceHistory"))
     
     static let `default` = ResourceHistoryDataStore(type: .reader)
-    class func oneTimeEditor() -> ResourceHistoryDataStore {
-        return ResourceHistoryDataStore(type: .editor)
-    }
     
     required init(type: CoreDataManagerType) {
+        
         context = ResourceHistoryDataStore.context(for: type)
     }
+    
     deinit {
-        save()
+        
+        save(errorHandler: presentOnMainThread)
     }
     
     let context: NSManagedObjectContext
 }
-
-extension ResourceHistoryDataStore {
-    func resources(in minites: [Int], older: Date) -> [Resource] {
-        let p = NSPredicate(format: "minute IN %@ AND date < %@", minites, older as NSDate)
-        guard let resources = try? objects(with: Resource.entity, predicate: p)
-            else { return [] }
-        return resources
-    }
-    func cerateResource() -> Resource? {
-        return insertNewObject(for: Resource.entity)
-    }
-}