• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javaandroidc++linuxc#objective-ccocoa誰得qtrubypythongamewindowsbathyscaphephpguic翻訳omegattwitterframeworktestbtronarduinovb.net計画中(planning stage)directxpreviewerゲームエンジンdom

main code repository.


Commit MetaInfo

修订版2ce69aad339dfed0000450e43e6a9f5169b97ccc (tree)
时间2018-03-18 10:40:33
作者masakih <masakih@user...>
Commitermasakih

Log Message

処理を簡素にした

更改概述

差异

--- a/KCD/CoreDataManager.swift
+++ b/KCD/CoreDataManager.swift
@@ -83,61 +83,50 @@ extension CoreDataProvider {
8383
8484 func save() throws {
8585
86- var caughtError: Error?
87- context.performAndWait {
88-
89- guard context.commitEditing() else {
90-
91- caughtError = CoreDataError.couldNotSave("\(String(describing: type(of: self))) unable to commit editing before saveing")
92- return
93- }
86+ // parentを辿ってsaveしていく
87+ func propagateSaveAsync(_ context: NSManagedObjectContext) {
9488
95- do {
89+ guard let parent = context.parent else {
9690
97- try context.save()
98-
99- } catch let error as NSError {
100-
101- caughtError = CoreDataError.couldNotSave(error.localizedDescription)
10291 return
10392 }
10493
105- guard let reader = context.parent else { return }
106-
107- // save parent context
108- var catchedError: NSError? = nil
109- reader.performAndWait {
94+ parent.perform {
11095
11196 do {
11297
113- try reader.save()
98+ try parent.save()
11499
115- guard let writer = reader.parent else {
116-
117- throw CoreDataError.couldNotSave("Could not get writer context.")
118- }
100+ propagateSaveAsync(parent)
119101
120- writer.performAndWait {
121-
122- do {
123-
124- try writer.save()
125-
126- } catch let error as NSError {
127-
128- catchedError = error
129- }
130- }
102+ } catch {
131103
132- } catch let error as NSError {
133-
134- catchedError = error
104+ Logger.shared.log("Could not save context as \(error)")
135105 }
136106 }
107+ }
108+
109+ var caughtError: Error?
110+ context.performAndWait {
137111
138- if let error = catchedError {
112+ guard context.commitEditing() else {
113+
114+ caughtError = CoreDataError.couldNotSave("Unable to commit editing before saveing")
115+ return
116+ }
117+
118+ do {
119+
120+ try context.save()
121+
122+ // save reader and writer context async.
123+ // non throw exceptions.
124+ propagateSaveAsync(context)
125+
126+ } catch let error as NSError {
139127
140128 caughtError = CoreDataError.couldNotSave(error.localizedDescription)
129+ return
141130 }
142131 }
143132