Page Menu
Home
Musing Studio
Search
Configure Global Search
Log In
Files
F14177233
CollectionListModel.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
CollectionListModel.swift
View Options
import
SwiftUI
import
CoreData
class
CollectionListModel
:
ObservableObject
{
@
Published
var
userCollections
=
[
WFACollection
]()
init
()
{
loadCachedUserCollections
()
}
func
loadCachedUserCollections
()
{
let
request
=
WFACollection
.
createFetchRequest
()
let
sort
=
NSSortDescriptor
(
key
:
"title"
,
ascending
:
true
)
request
.
sortDescriptors
=
[
sort
]
userCollections
=
[]
do
{
let
cachedCollections
=
try
PersistenceManager
.
persistentContainer
.
viewContext
.
fetch
(
request
)
userCollections
.
append
(
contentsOf
:
cachedCollections
)
}
catch
{
print
(
"Error: Failed to fetch cached user collections."
)
}
}
func
clearUserCollection
()
{
userCollections
=
[]
let
fetchRequest
:
NSFetchRequest
<
NSFetchRequestResult
>
=
NSFetchRequest
(
entityName
:
"WFACollection"
)
let
deleteRequest
=
NSBatchDeleteRequest
(
fetchRequest
:
fetchRequest
)
do
{
try
PersistenceManager
.
persistentContainer
.
persistentStoreCoordinator
.
execute
(
deleteRequest
,
with
:
PersistenceManager
.
persistentContainer
.
viewContext
)
}
catch
{
print
(
"Error: Failed to purge cached collections."
)
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-c++
Expires
Thu, Apr 2, 5:44 AM (19 h, 42 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3679141
Attached To
rWFSUI WriteFreely SwiftUI
Event Timeline
Log In to Comment