• 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

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

Log Message

saveメソッドを一本化

Ändern Zusammenfassung

Diff

--- a/KCD.xcodeproj/project.pbxproj
+++ b/KCD.xcodeproj/project.pbxproj
@@ -1153,13 +1153,13 @@
11531153 F4BEEEA818D88FF30006F70C /* CoreData */ = {
11541154 isa = PBXGroup;
11551155 children = (
1156- F4BDEEB11E73FE2000D689AE /* Entity.swift */,
11571156 F4E471281E46ECF1009B5AF4 /* CoreDataCore.swift */,
1158- F4C4A57E201464E300F8B732 /* CoreDataProviderExtension.swift */,
1159- F4FF44D71FA21BF200039F21 /* CoreDataManager.swift */,
11601157 F44AA2661E814A4400EED8BE /* MOCGenerator.swift */,
1158+ F4BDEEB11E73FE2000D689AE /* Entity.swift */,
1159+ F4FF44D71FA21BF200039F21 /* CoreDataManager.swift */,
11611160 F481D63E1F9105CB007E2CBE /* Entities.swift */,
11621161 F4FC3E8D1E4368BB00E41228 /* KCManagedObject.swift */,
1162+ F4C4A57E201464E300F8B732 /* CoreDataProviderExtension.swift */,
11631163 F4F9F8911C6BA26400D0EE76 /* KCD */,
11641164 F4F9F8921C6BA28200D0EE76 /* Local */,
11651165 F4F9F8931C6BA29500D0EE76 /* Temporary */,
--- a/KCD/BookmarkListViewController.swift
+++ b/KCD/BookmarkListViewController.swift
@@ -160,7 +160,7 @@ extension BookmarkListViewController: NSTableViewDelegate, NSTableViewDataSource
160160 bookmark.order = targetOrder + $0.offset + 1
161161 }
162162
163- store.save(errorHandler: store.presentOnMainThread)
163+ store.save()
164164
165165 self.bookmarkController.rearrangeObjects()
166166 self.reorderingBoolmarks()
--- a/KCD/BookmarkManager.swift
+++ b/KCD/BookmarkManager.swift
@@ -77,7 +77,7 @@ final class BookmarkManager: NSObject, NSMenuDelegate {
7777 return nil
7878 }
7979
80- editorStore.save(errorHandler: editorStore.presentOnMainThread)
80+ editorStore.save()
8181
8282 return new
8383 }
--- a/KCD/CoreDataManager.swift
+++ b/KCD/CoreDataManager.swift
@@ -30,8 +30,7 @@ protocol CoreDataProvider {
3030
3131 var context: NSManagedObjectContext { get }
3232
33- func save(errorHandler: (Error) -> Void)
34- func save() throws
33+ func save(errorHandler: @escaping (Error) -> Void)
3534 }
3635
3736 protocol CoreDataAccessor: CoreDataProvider {
@@ -55,6 +54,21 @@ protocol CoreDataManager: CoreDataAccessor {
5554 static func oneTimeEditor() -> Self
5655 }
5756
57+func presentOnMainThread(_ error: Error) {
58+
59+ if Thread.isMainThread {
60+
61+ NSApp.presentError(error)
62+
63+ } else {
64+
65+ DispatchQueue.main.sync {
66+
67+ _ = NSApp.presentError(error)
68+ }
69+ }
70+}
71+
5872 // MARK: - Extension
5973 extension CoreDataProvider {
6074
@@ -67,19 +81,7 @@ extension CoreDataProvider {
6781 }
6882 }
6983
70- func save(errorHandler: (Error) -> Void) {
71-
72- do {
73-
74- try save()
75-
76- } catch {
77-
78- errorHandler(error)
79- }
80- }
81-
82- func save() throws {
84+ func save(errorHandler: @escaping (Error) -> Void = presentOnMainThread) {
8385
8486 // parentを辿ってsaveしていく
8587 func propagateSaveAsync(_ context: NSManagedObjectContext) {
@@ -99,17 +101,16 @@ extension CoreDataProvider {
99101
100102 } catch {
101103
102- Logger.shared.log("Could not save context as \(error)")
104+ errorHandler(error)
103105 }
104106 }
105107 }
106108
107- var caughtError: Error?
108109 context.performAndWait {
109110
110111 guard context.commitEditing() else {
111112
112- caughtError = CoreDataError.couldNotSave("Unable to commit editing before saveing")
113+ errorHandler(CoreDataError.couldNotSave("Unable to commit editing before saveing"))
113114 return
114115 }
115116
@@ -123,28 +124,7 @@ extension CoreDataProvider {
123124
124125 } catch let error as NSError {
125126
126- caughtError = CoreDataError.couldNotSave(error.localizedDescription)
127- return
128- }
129- }
130-
131- if let error = caughtError {
132-
133- throw error
134- }
135- }
136-
137- func presentOnMainThread(_ error: Error) {
138-
139- if Thread.isMainThread {
140-
141- NSApp.presentError(error)
142-
143- } else {
144-
145- DispatchQueue.main.sync {
146-
147- _ = NSApp.presentError(error)
127+ errorHandler(CoreDataError.couldNotSave(error.localizedDescription))
148128 }
149129 }
150130 }
--- a/KCD/GuardShelterCommand.swift
+++ b/KCD/GuardShelterCommand.swift
@@ -108,7 +108,7 @@ final class GuardShelterCommand: JSONCommand {
108108 let store = TemporaryDataStore.oneTimeEditor()
109109 store.sync {
110110 store.notEnsuredGuardEscaped().forEach(store.delete)
111- store.save(errorHandler: store.presentOnMainThread)
111+ store.save()
112112 }
113113 Thread.sleep(forTimeInterval: 0.1)
114114 notify()
@@ -119,7 +119,7 @@ final class GuardShelterCommand: JSONCommand {
119119 let store = TemporaryDataStore.oneTimeEditor()
120120 store.sync {
121121 store.guardEscaped().forEach(store.delete)
122- store.save(errorHandler: store.presentOnMainThread)
122+ store.save()
123123 }
124124 Thread.sleep(forTimeInterval: 0.1)
125125 notify()
@@ -130,7 +130,7 @@ final class GuardShelterCommand: JSONCommand {
130130 let store = TemporaryDataStore.oneTimeEditor()
131131 store.sync {
132132 store.guardEscaped().forEach { $0.ensured = true }
133- store.save(errorHandler: store.presentOnMainThread)
133+ store.save()
134134 }
135135 Thread.sleep(forTimeInterval: 0.1)
136136 notify()
--- a/KCD/HistoryTableViewController.swift
+++ b/KCD/HistoryTableViewController.swift
@@ -80,7 +80,7 @@ class HistoryTableViewController: NSViewController {
8080 history.mark = !history.mark
8181 }
8282
83- store.save(errorHandler: store.presentOnMainThread)
83+ store.save()
8484 }
8585 }
8686
--- a/KCD/JSONMapper.swift
+++ b/KCD/JSONMapper.swift
@@ -171,7 +171,7 @@ extension JSONMapper {
171171 }
172172
173173 finishOperating()
174- store.save(errorHandler: store.presentOnMainThread)
174+ store.save()
175175 }
176176
177177 func commit() {
--- a/KCD/MapInfoCommand.swift
+++ b/KCD/MapInfoCommand.swift
@@ -20,7 +20,7 @@ final class MapInfoCommand: JSONCommand {
2020 let store = ServerDataStore.oneTimeEditor()
2121 store.sync {
2222 store.airBases().forEach(store.delete)
23- store.save(errorHandler: store.presentOnMainThread)
23+ store.save()
2424 }
2525
2626 AirBaseMapper(apiResponse).commit()