Page Menu
Home
Musing Studio
Search
Configure Global Search
Log In
Files
F12142631
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
{
@
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
{
try
collectionsController
.
performFetch
()
list
=
collectionsController
.
fetchedObjects
??
[]
}
catch
{
print
(
"Failed to fetch collections!"
)
}
}
}
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, 11:32 PM (1 d, 1 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3440904
Attached To
rWFSUI WriteFreely SwiftUI
Event Timeline
Log In to Comment