fix: AccountList scene not display items issue

This commit is contained in:
CMK 2022-10-31 14:47:13 +08:00
parent 3100c59a3b
commit 668a1d28e2
3 changed files with 19 additions and 1 deletions

View File

@ -216,7 +216,7 @@ extension SceneCoordinator {
let rootViewController: UIViewController
do {
let request = MastodonAuthentication.sortedFetchRequest
let request = MastodonAuthentication.activeSortedFetchRequest // use active order
let _authentication = try appContext.managedObjectContext.fetch(request).first
let _authContext = _authentication.flatMap { AuthContext(authentication: $0) }
self.authContext = _authContext

View File

@ -50,6 +50,12 @@ final class AccountListViewModel: NSObject {
// end init
mastodonAuthenticationFetchedResultsController.delegate = self
do {
try mastodonAuthenticationFetchedResultsController.performFetch()
authentications = mastodonAuthenticationFetchedResultsController.fetchedObjects?.compactMap { $0.asRecrod } ?? []
} catch {
assertionFailure(error.localizedDescription)
}
$authentications
.receive(on: DispatchQueue.main)

View File

@ -148,6 +148,18 @@ extension MastodonAuthentication: Managed {
public static var defaultSortDescriptors: [NSSortDescriptor] {
return [NSSortDescriptor(keyPath: \MastodonAuthentication.createdAt, ascending: false)]
}
public static var activeSortDescriptors: [NSSortDescriptor] {
return [NSSortDescriptor(keyPath: \MastodonAuthentication.activedAt, ascending: false)]
}
}
extension MastodonAuthentication {
public static var activeSortedFetchRequest: NSFetchRequest<MastodonAuthentication> {
let request = NSFetchRequest<MastodonAuthentication>(entityName: entityName)
request.sortDescriptors = activeSortDescriptors
return request
}
}
extension MastodonAuthentication {