Fix retain cycle between MastodonController/MastodonCache
The cache should only store a weak reference to the controller, so that when the controller is deinit'd the cache is as well.
This commit is contained in:
parent
8eb6f6f573
commit
2f630f2f8f
|
@ -20,7 +20,7 @@ class MastodonCache {
|
|||
let statusSubject = PassthroughSubject<Status, Never>()
|
||||
let accountSubject = PassthroughSubject<Account, Never>()
|
||||
|
||||
let mastodonController: MastodonController
|
||||
weak var mastodonController: MastodonController?
|
||||
|
||||
init(mastodonController: MastodonController) {
|
||||
self.mastodonController = mastodonController
|
||||
|
@ -43,6 +43,9 @@ class MastodonCache {
|
|||
}
|
||||
|
||||
func status(for id: String, completion: @escaping (Status?) -> Void) {
|
||||
guard let mastodonController = mastodonController else {
|
||||
fatalError("The MastodonController for this cache has been deinitialized, so this cache should no longer exist. Are you storing a strong reference to it?")
|
||||
}
|
||||
let request = Client.getStatus(id: id)
|
||||
mastodonController.run(request) { response in
|
||||
guard case let .success(status, _) = response else {
|
||||
|
@ -73,6 +76,9 @@ class MastodonCache {
|
|||
}
|
||||
|
||||
func account(for id: String, completion: @escaping (Account?) -> Void) {
|
||||
guard let mastodonController = mastodonController else {
|
||||
fatalError("The MastodonController for this cache has been deinitialized, so this cache should no longer exist. Are you storing a strong reference to it?")
|
||||
}
|
||||
let request = Client.getAccount(id: id)
|
||||
mastodonController.run(request) { response in
|
||||
guard case let .success(account, _) = response else {
|
||||
|
@ -102,6 +108,9 @@ class MastodonCache {
|
|||
}
|
||||
|
||||
func relationship(for id: String, completion: @escaping (Relationship?) -> Void) {
|
||||
guard let mastodonController = mastodonController else {
|
||||
fatalError("The MastodonController for this cache has been deinitialized, so this cache should no longer exist. Are you storing a strong reference to it?")
|
||||
}
|
||||
let request = Client.getRelationships(accounts: [id])
|
||||
mastodonController.run(request) { response in
|
||||
guard case let .success(relationships, _) = response,
|
||||
|
|
Loading…
Reference in New Issue