Refactoring

This commit is contained in:
Justin Mazzocchi 2021-01-05 14:38:15 -08:00
parent 98ac456be6
commit 61d1a3619d
No known key found for this signature in database
GPG key ID: E223E6937AAFB01C
3 changed files with 16 additions and 22 deletions

View file

@ -32,19 +32,15 @@ public extension MediaProcessingService {
return Future<Data, Error> { 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)) }
promise(.failure(error))
} else if let url = url {
if uniformType.conforms(to: .image) {
return promise(imageData(url: url, type: uniformType))
promise(imageData(url: url, type: uniformType))
} else {
do {
return try promise(.success(Data(contentsOf: url)))
} catch {
return promise(.failure(error))
promise(Result { try Data(contentsOf: url) })
}
} else {
promise(.failure(MediaProcessingError.fileURLNotFound))
}
}
}

View file

@ -44,10 +44,10 @@ private extension UserNotificationService {
Future<Bool, Error> { 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()

View file

@ -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