Page Menu
Home
Musing Studio
Search
Configure Global Search
Log In
Files
F14172345
PostEditorModel.swift
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Subscribers
None
PostEditorModel.swift
View Options
import
Foundation
import
CoreData
struct
PostEditorModel
{
let
lastDraftObjectURLKey
=
"lastDraftObjectURLKey"
private
(
set
)
var
lastDraft
:
WFAPost
?
mutating
func
setLastDraft
(
_
post
:
WFAPost
)
{
lastDraft
=
post
UserDefaults
.
standard
.
set
(
post
.
objectID
.
uriRepresentation
(),
forKey
:
lastDraftObjectURLKey
)
}
mutating
func
fetchLastDraft
()
->
WFAPost
?
{
let
coordinator
=
LocalStorageManager
.
persistentContainer
.
persistentStoreCoordinator
// See if we have a lastDraftObjectURI
guard
let
lastDraftObjectURI
=
UserDefaults
.
standard
.
url
(
forKey
:
lastDraftObjectURLKey
)
else
{
return
nil
}
// See if we can get an ObjectID from the URI representation
guard
let
lastDraftObjectID
=
coordinator
.
managedObjectID
(
forURIRepresentation
:
lastDraftObjectURI
)
else
{
return
nil
}
lastDraft
=
LocalStorageManager
.
persistentContainer
.
viewContext
.
object
(
with
:
lastDraftObjectID
)
as
?
WFAPost
return
lastDraft
}
mutating
func
clearLastDraft
()
{
lastDraft
=
nil
UserDefaults
.
standard
.
removeObject
(
forKey
:
lastDraftObjectURLKey
)
}
}
File Metadata
Details
Attached
Mime Type
text/x-c
Expires
Thu, Apr 2, 2:59 AM (1 d, 9 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3673553
Attached To
rWFSUI WriteFreely SwiftUI
Event Timeline
Log In to Comment