From a20b2911b7b0d5fa9cb1157d26af4f588263d58b Mon Sep 17 00:00:00 2001 From: Angelo Stavrow Date: Thu, 10 Sep 2020 12:29:24 -0400 Subject: [PATCH] Save managed object context before publishing a local post --- Shared/PostEditor/PostEditorView.swift | 11 +++++++++-- .../xcschemes/xcschememanagement.plist | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Shared/PostEditor/PostEditorView.swift b/Shared/PostEditor/PostEditorView.swift index bd7714f..88003be 100644 --- a/Shared/PostEditor/PostEditorView.swift +++ b/Shared/PostEditor/PostEditorView.swift @@ -30,8 +30,7 @@ struct PostEditorView: View { } ToolbarItem(placement: .primaryAction) { Button(action: { - model.publish(post: post) - post.status = PostStatus.published.rawValue + publishPost() }, label: { Image(systemName: "paperplane") }) @@ -50,6 +49,14 @@ struct PostEditorView: View { } }) } + + private func publishPost() { + DispatchQueue.main.async { + LocalStorageManager().saveContext() + model.posts.loadCachedPosts() + model.publish(post: post) + } + } } struct PostEditorView_Previews: PreviewProvider { diff --git a/WriteFreely-MultiPlatform.xcodeproj/xcuserdata/angelo.xcuserdatad/xcschemes/xcschememanagement.plist b/WriteFreely-MultiPlatform.xcodeproj/xcuserdata/angelo.xcuserdatad/xcschemes/xcschememanagement.plist index 2723ebe..6cd8075 100644 --- a/WriteFreely-MultiPlatform.xcodeproj/xcuserdata/angelo.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/WriteFreely-MultiPlatform.xcodeproj/xcuserdata/angelo.xcuserdatad/xcschemes/xcschememanagement.plist @@ -7,12 +7,12 @@ WriteFreely-MultiPlatform (iOS).xcscheme_^#shared#^_ orderHint - 0 + 1 WriteFreely-MultiPlatform (macOS).xcscheme_^#shared#^_ orderHint - 1 + 0