From 61d1a3619dfee0be50ffb10229ba298f526bbc15 Mon Sep 17 00:00:00 2001 From: Justin Mazzocchi <2831158+jzzocc@users.noreply.github.com> Date: Tue, 5 Jan 2021 14:38:15 -0800 Subject: [PATCH] Refactoring --- .../Services/MediaProcessingService.swift | 20 ++++++++----------- .../Services/UserNotificationService.swift | 6 +++--- .../Utilities/WebAuthSession.swift | 12 +++++------ 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/ServiceLayer/Sources/ServiceLayer/Services/MediaProcessingService.swift b/ServiceLayer/Sources/ServiceLayer/Services/MediaProcessingService.swift index 706429e..64559f3 100644 --- a/ServiceLayer/Sources/ServiceLayer/Services/MediaProcessingService.swift +++ b/ServiceLayer/Sources/ServiceLayer/Services/MediaProcessingService.swift @@ -32,19 +32,15 @@ public extension MediaProcessingService { return Future { promise in itemProvider.loadFileRepresentation(forTypeIdentifier: uniformType.identifier) { url, error in if let error = error { - return promise(.failure(error)) - } - - guard let url = url else { return promise(.failure(MediaProcessingError.fileURLNotFound)) } - - if uniformType.conforms(to: .image) { - return promise(imageData(url: url, type: uniformType)) - } else { - do { - return try promise(.success(Data(contentsOf: url))) - } catch { - return promise(.failure(error)) + promise(.failure(error)) + } else if let url = url { + if uniformType.conforms(to: .image) { + promise(imageData(url: url, type: uniformType)) + } else { + promise(Result { try Data(contentsOf: url) }) } + } else { + promise(.failure(MediaProcessingError.fileURLNotFound)) } } } diff --git a/ServiceLayer/Sources/ServiceLayer/Services/UserNotificationService.swift b/ServiceLayer/Sources/ServiceLayer/Services/UserNotificationService.swift index 402a893..a0d50cd 100644 --- a/ServiceLayer/Sources/ServiceLayer/Services/UserNotificationService.swift +++ b/ServiceLayer/Sources/ServiceLayer/Services/UserNotificationService.swift @@ -44,10 +44,10 @@ private extension UserNotificationService { Future { promise in userNotificationClient.requestAuthorization([.alert, .sound, .badge, .provisional]) { granted, error in if let error = error { - return promise(.failure(error)) + promise(.failure(error)) + } else { + promise(.success(granted)) } - - return promise(.success(granted)) } } .eraseToAnyPublisher() diff --git a/ServiceLayer/Sources/ServiceLayer/Utilities/WebAuthSession.swift b/ServiceLayer/Sources/ServiceLayer/Utilities/WebAuthSession.swift index ee3a689..fc876f3 100644 --- a/ServiceLayer/Sources/ServiceLayer/Utilities/WebAuthSession.swift +++ b/ServiceLayer/Sources/ServiceLayer/Utilities/WebAuthSession.swift @@ -22,14 +22,12 @@ extension WebAuthSession { url: url, callbackURLScheme: callbackURLScheme) { oauthCallbackURL, error in if let error = error { - return promise(.failure(error)) + promise(.failure(error)) + } else if let oauthCallbackURL = oauthCallbackURL { + promise(.success(oauthCallbackURL)) + } else { + promise(.failure(URLError(.unknown))) } - - guard let oauthCallbackURL = oauthCallbackURL else { - return promise(.failure(URLError(.unknown))) - } - - return promise(.success(oauthCallbackURL)) } webAuthSession.presentationContextProvider = presentationContextProvider