Page Menu
Home
Musing Studio
Search
Configure Global Search
Log In
Files
F12142530
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
:
NSObject
,
ObservableObject
{
private
let
logger
=
Logging
(
for
:
String
(
describing
:
CollectionListModel
.
self
))
@
Published
var
list
:
[
WFACollection
]
=
[]
private
let
collectionsController
:
NSFetchedResultsController
<
WFACollection
>
init
(
managedObjectContext
:
NSManagedObjectContext
)
{
collectionsController
=
NSFetchedResultsController
(
fetchRequest
:
WFACollection
.
collectionsFetchRequest
,
managedObjectContext
:
managedObjectContext
,
sectionNameKeyPath
:
nil
,
cacheName
:
nil
)
super
.
init
()
collectionsController
.
delegate
=
self
do
{
logger
.
log
(
"Fetching collections from local store..."
)
try
collectionsController
.
performFetch
()
list
=
collectionsController
.
fetchedObjects
??
[]
logger
.
log
(
"Fetched collections from local store."
)
}
catch
{
logger
.
logCrashAndSetFlag
(
error
:
LocalStoreError
.
couldNotFetchCollections
)
}
}
}
extension
CollectionListModel
:
NSFetchedResultsControllerDelegate
{
func
controllerDidChangeContent
(
_
controller
:
NSFetchedResultsController
<
NSFetchRequestResult
>)
{
guard
let
collections
=
controller
.
fetchedObjects
as
?
[
WFACollection
]
else
{
return
}
self
.
list
=
collections
}
}
extension
WFACollection
{
static
var
collectionsFetchRequest
:
NSFetchRequest
<
WFACollection
>
{
let
request
:
NSFetchRequest
<
WFACollection
>
=
WFACollection
.
createFetchRequest
()
request
.
sortDescriptors
=
[
NSSortDescriptor
(
keyPath
:
\
WFACollection
.
title
,
ascending
:
true
)]
return
request
}
}
File Metadata
Details
Attached
Mime Type
text/x-c++
Expires
Thu, Oct 9, 10:22 PM (1 d, 4 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3437796
Attached To
rWFSUI WriteFreely SwiftUI
Event Timeline
Log In to Comment