• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#objective-cqt誰得windowscocoapythonphprubygameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwittertestdomvb.netdirectxbtronarduinopreviewerゲームエンジン

main code repository.


Commit MetaInfo

Revisionb4920759628ea68cd1a6f4b5738ad264652bbc31 (tree)
Zeit2018-03-18 10:40:33
Autormasakih <masakih@user...>
Commitermasakih

Log Message

保存用NSManagedObjectContextを用いいるようにした

Ändern Zusammenfassung

Diff

--- a/KCD/CoreDataCore.swift
+++ b/KCD/CoreDataCore.swift
@@ -40,7 +40,8 @@ struct CoreDataConfiguration {
4040 struct CoreDataCore {
4141
4242 let config: CoreDataConfiguration
43- let parentContext: NSManagedObjectContext
43+ let writerContext: NSManagedObjectContext
44+ let readerContext: NSManagedObjectContext
4445 private let model: NSManagedObjectModel
4546 private let coordinator: NSPersistentStoreCoordinator
4647
@@ -50,7 +51,11 @@ struct CoreDataCore {
5051
5152 do {
5253
53- (model, coordinator, parentContext) = try MOCGenerator(config).genarate()
54+ (model, coordinator, writerContext) = try MOCGenerator(config).genarate()
55+
56+ readerContext = NSManagedObjectContext(concurrencyType: .mainQueueConcurrencyType)
57+ readerContext.parent = writerContext
58+ readerContext.undoManager = nil
5459
5560 } catch {
5661
@@ -62,7 +67,7 @@ struct CoreDataCore {
6267 func editorContext() -> NSManagedObjectContext {
6368
6469 let moc = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType)
65- moc.parent = parentContext
70+ moc.parent = readerContext
6671 moc.undoManager = nil
6772
6873 return moc
--- a/KCD/CoreDataManager.swift
+++ b/KCD/CoreDataManager.swift
@@ -63,7 +63,7 @@ extension CoreDataProvider {
6363 static func context(for type: CoreDataManagerType) -> NSManagedObjectContext {
6464
6565 switch type {
66- case .reader: return core.parentContext
66+ case .reader: return core.readerContext
6767
6868 case .editor: return core.editorContext()
6969 }
@@ -102,15 +102,32 @@ extension CoreDataProvider {
102102 return
103103 }
104104
105- guard let parent = context.parent else { return }
105+ guard let reader = context.parent else { return }
106106
107107 // save parent context
108108 var catchedError: NSError? = nil
109- parent.performAndWait {
109+ reader.performAndWait {
110110
111111 do {
112112
113- try parent.save()
113+ try reader.save()
114+
115+ guard let writer = reader.parent else {
116+
117+ throw CoreDataError.couldNotSave("Could not get writer context.")
118+ }
119+
120+ writer.performAndWait {
121+
122+ do {
123+
124+ try writer.save()
125+
126+ } catch let error as NSError {
127+
128+ catchedError = error
129+ }
130+ }
114131
115132 } catch let error as NSError {
116133
--- a/KCD/MOCGenerator.swift
+++ b/KCD/MOCGenerator.swift
@@ -120,7 +120,7 @@ final class MOCGenerator {
120120
121121 private func createContext(_ coordinator: NSPersistentStoreCoordinator) -> NSManagedObjectContext {
122122
123- let moc = NSManagedObjectContext(concurrencyType: .mainQueueConcurrencyType)
123+ let moc = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType)
124124 moc.persistentStoreCoordinator = coordinator
125125 moc.undoManager = nil
126126