Page Menu
Home
Musing Studio
Search
Configure Global Search
Log In
Files
F14177225
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
LocalStorageManager
.
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
LocalStorageManager
.
persistentContainer
.
persistentStoreCoordinator
.
execute
(
deleteRequest
,
with
:
LocalStorageManager
.
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 (14 h, 35 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3679323
Attached To
rWFSUI WriteFreely SwiftUI
Event Timeline
Log In to Comment