OSDN Git Service

CoreDataIntormationのイニシャライザにデフォルトバリューをもたせた
authormasakih <masakih@users.sourceforge.jp>
Sun, 12 Mar 2017 07:22:59 +0000 (16:22 +0900)
committermasakih <masakih@users.sourceforge.jp>
Sun, 12 Mar 2017 07:22:59 +0000 (16:22 +0900)
KCD/BookmarkDataStore.swift
KCD/CoreDataCore.swift
KCD/LocalDataStore.swift
KCD/ResourceHistoryDataStore.swift
KCD/ServerDataStore.swift
KCD/TemporaryDataStore.swift

index d01204e..9e929bd 100644 (file)
@@ -9,14 +9,7 @@
 import Cocoa
 
 extension CoreDataIntormation {
-    static let bookmark = CoreDataIntormation(
-        modelName: "Bookmark",
-        storeFileName: "Bookmark.storedata",
-        storeOptions: [NSMigratePersistentStoresAutomaticallyOption: true,
-                       NSInferMappingModelAutomaticallyOption: true],
-        storeType: NSSQLiteStoreType,
-        deleteAndRetry: false
-    )
+    static let bookmark = CoreDataIntormation("Bookmark")
 }
 extension CoreDataCore {
     static let bookmark = CoreDataCore(.bookmark)
index db5b6cd..304e9b8 100644 (file)
@@ -25,6 +25,23 @@ struct CoreDataIntormation {
     let storeOptions: Dictionary<AnyHashable, Any>
     let storeType: String
     let deleteAndRetry: Bool
+    
+    private static let defaultOptions: [AnyHashable: Any] = [
+        NSMigratePersistentStoresAutomaticallyOption: true,
+        NSInferMappingModelAutomaticallyOption: true
+    ]
+    
+    init(_ modelName: String,
+         storeFileName: String? = nil,
+         storeOptions: [AnyHashable: Any] = defaultOptions,
+         storeType: String = NSSQLiteStoreType,
+         deleteAndRetry: Bool = false) {
+        self.modelName = modelName
+        self.storeFileName = storeFileName ?? "\(modelName).storedata"
+        self.storeOptions = storeOptions
+        self.storeType = storeType
+        self.deleteAndRetry = deleteAndRetry
+    }
 }
 
 struct CoreDataCore {
index 147da6a..8ebb439 100644 (file)
@@ -9,14 +9,7 @@
 import Cocoa
 
 extension CoreDataIntormation {
-    static let local = CoreDataIntormation(
-        modelName: "LocalData",
-        storeFileName: "LocalData.storedata",
-        storeOptions: [NSMigratePersistentStoresAutomaticallyOption: true,
-                       NSInferMappingModelAutomaticallyOption: true],
-        storeType: NSSQLiteStoreType,
-        deleteAndRetry: false
-    )
+    static let local = CoreDataIntormation("LocalData")
 }
 extension CoreDataCore {
     static let local = CoreDataCore(.local)
index 546c90b..746eb01 100644 (file)
@@ -9,14 +9,7 @@
 import Cocoa
 
 extension CoreDataIntormation {
-    static let resourceHistory = CoreDataIntormation(
-        modelName: "ResourceHistory",
-        storeFileName: "ResourceHistory.storedata",
-        storeOptions: [NSMigratePersistentStoresAutomaticallyOption: true,
-                       NSInferMappingModelAutomaticallyOption: true],
-        storeType: NSSQLiteStoreType,
-        deleteAndRetry: false
-    )
+    static let resourceHistory = CoreDataIntormation("ResourceHistory")
 }
 extension CoreDataCore {
     static let resourceHistory = CoreDataCore(.resourceHistory)
index 42efa5a..5714a74 100644 (file)
@@ -1,6 +1,6 @@
 //
 //  ServerDataStore.swift
-//  D
+//  KCD
 //
 //  Created by Hori,Masaki on 2017/01/07.
 //  Copyright © 2017年 Hori,Masaki. All rights reserved.
@@ -9,14 +9,7 @@
 import Cocoa
 
 extension CoreDataIntormation {
-    static let kcd = CoreDataIntormation(
-        modelName: "KCD",
-        storeFileName: "KCD.storedata",
-        storeOptions: [NSMigratePersistentStoresAutomaticallyOption: true,
-                       NSInferMappingModelAutomaticallyOption: true],
-        storeType: NSSQLiteStoreType,
-        deleteAndRetry: true
-    )
+    static let kcd = CoreDataIntormation("KCD", deleteAndRetry: true)
 }
 extension CoreDataCore {
     static let kcd = CoreDataCore(.kcd)
index ad1df7f..98856b3 100644 (file)
@@ -1,6 +1,6 @@
 //
 //  TemporaryDataStore.swift
-//  D
+//  KCD
 //
 //  Created by Hori,Masaki on 2017/01/06.
 //  Copyright © 2017年 Hori,Masaki. All rights reserved.
@@ -9,12 +9,10 @@
 import Cocoa
 
 extension CoreDataIntormation {
-    static let temporary = CoreDataIntormation(
-        modelName: "Temporary",
-        storeFileName: ":memory:",
-        storeOptions: [:],
-        storeType: NSInMemoryStoreType,
-        deleteAndRetry: false
+    static let temporary = CoreDataIntormation("Temporary",
+                                               storeFileName: ":memory:",
+                                               storeOptions: [:],
+                                               storeType: NSInMemoryStoreType
     )
 }
 extension CoreDataCore {