Page Menu
Home
Musing Studio
Search
Configure Global Search
Log In
Files
F12272721
PostEditorModel.swift
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1007 B
Subscribers
None
PostEditorModel.swift
View Options
import
SwiftUI
import
CoreData
enum
PostAppearance
:
String
{
case
sans
=
"OpenSans-Regular"
case
mono
=
"Hack-Regular"
case
serif
=
"Lora-Regular"
}
struct
PostEditorModel
{
@
AppStorage
(
"lastDraftURL"
)
private
var
lastDraftURL
:
URL
?
func
saveLastDraft
(
_
post
:
WFAPost
)
{
self
.
lastDraftURL
=
post
.
status
!=
PostStatus
.
published
.
rawValue
?
post
.
objectID
.
uriRepresentation
()
:
nil
}
func
clearLastDraft
()
{
self
.
lastDraftURL
=
nil
}
func
fetchLastDraftFromUserDefaults
()
->
WFAPost
?
{
guard
let
postURL
=
lastDraftURL
else
{
return
nil
}
let
coordinator
=
LocalStorageManager
.
persistentContainer
.
persistentStoreCoordinator
guard
let
postManagedObjectID
=
coordinator
.
managedObjectID
(
forURIRepresentation
:
postURL
)
else
{
return
nil
}
guard
let
post
=
LocalStorageManager
.
persistentContainer
.
viewContext
.
object
(
with
:
postManagedObjectID
)
as
?
WFAPost
else
{
return
nil
}
return
post
}
}
File Metadata
Details
Attached
Mime Type
text/x-c
Expires
Thu, Nov 6, 5:33 AM (1 d, 18 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3470839
Attached To
rWFSUI WriteFreely SwiftUI
Event Timeline
Log In to Comment