Calling the completion handler in the case of a nil self

This commit is contained in:
Alexander Heinrich
2021-04-29 09:38:16 +02:00
parent c618aab843
commit ba174196c0
4 changed files with 23 additions and 6 deletions

View File

@@ -33,7 +33,10 @@ class FindMyController: ObservableObject {
// Decrypt the reports with the imported keys
DispatchQueue.global(qos: .background).async { [weak self] in
guard let self = self else { return }
guard let self = self else {
completion()
return
}
var d = self.devices
// Add the reports to the according device by finding the right key for the report
@@ -110,7 +113,10 @@ class FindMyController: ObservableObject {
func fetchReports(with searchPartyToken: Data, completion: @escaping (Error?) -> Void) {
DispatchQueue.global(qos: .background).async { [weak self] in
guard let self = self else { return }
guard let self = self else {
completion(FindMyErrors.objectReleased)
return
}
let fetchReportGroup = DispatchGroup()
let fetcher = ReportsFetcher()
@@ -169,9 +175,13 @@ class FindMyController: ObservableObject {
#endif
DispatchQueue.main.async { [weak self] in
self?.devices = devices
guard let self = self else {
completion(FindMyErrors.objectReleased)
return
}
self.devices = devices
self?.decryptReports {
self.decryptReports {
completion(nil)
}
@@ -230,4 +240,5 @@ class FindMyController: ObservableObject {
enum FindMyErrors: Error {
case decodingPlistFailed(message: String)
case objectReleased
}

View File

@@ -161,7 +161,10 @@ class AccessoryController: ObservableObject {
/// - Parameter completion: called when the reports have been succesfully downloaded or the request has failed
func downloadLocationReports(completion: @escaping (Result<Void, OpenHaystackMainView.AlertType>) -> Void) {
AnisetteDataManager.shared.requestAnisetteData { [weak self] result in
guard let self = self else { return }
guard let self = self else {
completion(.failure(.noReportsFound))
return
}
switch result {
case .failure(_):
completion(.failure(.activatePlugin))

View File

@@ -46,7 +46,7 @@ class AccessoryAnnotationView: MKAnnotationView {
guard let accessory = (self.annotation as? AccessoryAnnotation)?.accessory else { return }
self.pinView?.removeFromSuperview()
self.pinView = nil
self.pinView = NSHostingView(rootView: AccessoryPinView(accessory: accessory)) // TODO: LEAK! This view is not release properly
self.pinView = NSHostingView(rootView: AccessoryPinView(accessory: accessory)) // TODO: LEAK! This view is not release properly
self.addSubview(pinView!)