File tree Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change 1
- import Foundation
1
+ import SwiftUI
2
2
import CoreData
3
3
4
4
enum PostAppearance : String {
@@ -8,5 +8,25 @@ enum PostAppearance: String {
8
8
}
9
9
10
10
struct PostEditorModel {
11
+ @AppStorage ( " lastDraftURL " ) private var lastDraftURL : URL ?
11
12
13
+ func saveLastDraft( _ post: WFAPost ) {
14
+ self . lastDraftURL = post. status != PostStatus . published. rawValue ? post. objectID. uriRepresentation ( ) : nil
15
+ }
16
+
17
+ func clearLastDraft( ) {
18
+ self . lastDraftURL = nil
19
+ }
20
+
21
+ func fetchLastDraftFromUserDefaults( ) -> WFAPost ? {
22
+ guard let postURL = lastDraftURL else { return nil }
23
+
24
+ let coordinator = LocalStorageManager . persistentContainer. persistentStoreCoordinator
25
+ guard let postManagedObjectID = coordinator. managedObjectID ( forURIRepresentation: postURL) else { return nil }
26
+ guard let post = LocalStorageManager . persistentContainer. viewContext. object (
27
+ with: postManagedObjectID
28
+ ) as? WFAPost else { return nil }
29
+
30
+ return post
31
+ }
12
32
}
You can’t perform that action at this time.
0 commit comments