From ea7ba1e25fed0198ec210c5b6a38c7a3ac57d1d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20K=C3=B6tte?= Date: Tue, 13 Dec 2022 15:09:38 +0100 Subject: [PATCH] Use shorthand optional binding --- Sources/Wealthsimple/Token.swift | 4 ++-- Sources/Wealthsimple/WealthsimpleAccount.swift | 4 ++-- Sources/Wealthsimple/WealthsimpleDownloader.swift | 8 ++++---- Sources/Wealthsimple/WealthsimplePosition.swift | 6 +++--- Sources/Wealthsimple/WealthsimpleTransaction.swift | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Sources/Wealthsimple/Token.swift b/Sources/Wealthsimple/Token.swift index 94feaca..492db17 100644 --- a/Sources/Wealthsimple/Token.swift +++ b/Sources/Wealthsimple/Token.swift @@ -130,8 +130,8 @@ struct Token { credentialStorage: CredentialStorage, completion: @escaping (Result) -> Void ) { - guard let data = data else { - if let error = error { + guard let data else { + if let error { completion(.failure(TokenError.httpError(error: error.localizedDescription))) } else { completion(.failure(TokenError.noDataReceived)) diff --git a/Sources/Wealthsimple/WealthsimpleAccount.swift b/Sources/Wealthsimple/WealthsimpleAccount.swift index 4339089..0d3fc67 100644 --- a/Sources/Wealthsimple/WealthsimpleAccount.swift +++ b/Sources/Wealthsimple/WealthsimpleAccount.swift @@ -112,8 +112,8 @@ struct WealthsimpleAccount: Account { } private static func handleResponse(data: Data?, response: URLResponse?, error: Error?, completion: @escaping (Result<[Account], AccountError>) -> Void) { - guard let data = data else { - if let error = error { + guard let data else { + if let error { completion(.failure(AccountError.httpError(error: error.localizedDescription))) } else { completion(.failure(AccountError.noDataReceived)) diff --git a/Sources/Wealthsimple/WealthsimpleDownloader.swift b/Sources/Wealthsimple/WealthsimpleDownloader.swift index 3408e1e..c36fffa 100644 --- a/Sources/Wealthsimple/WealthsimpleDownloader.swift +++ b/Sources/Wealthsimple/WealthsimpleDownloader.swift @@ -53,7 +53,7 @@ public final class WealthsimpleDownloader { /// Authneticates against the API. Call before calling any other method. /// - Parameter completion: Gets an error in case something went wrong, otherwise nil public func authenticate(completion: @escaping (Error?) -> Void) { - if let token = token { + if let token { token.refreshIfNeeded { switch $0 { case .failure: @@ -82,7 +82,7 @@ public final class WealthsimpleDownloader { /// Get all Accounts the user has access to /// - Parameter completion: Result with an array of `Account`s or an `Account.AccountError` public func getAccounts(completion: @escaping (Result<[Account], AccountError>) -> Void) { - guard let token = token else { + guard let token else { completion(.failure(.tokenError(.noToken))) return } @@ -102,7 +102,7 @@ public final class WealthsimpleDownloader { /// - date: Date of which the positions should be downloaded. If not date is provided, not date is sent to the API. The API falls back to the current date. /// - completion: Result with an array of `Position`s or an `Position.PositionError` public func getPositions(in account: Account, date: Date?, completion: @escaping (Result<[Position], PositionError>) -> Void) { - guard let token = token else { + guard let token else { completion(.failure(.tokenError(.noToken))) return } @@ -122,7 +122,7 @@ public final class WealthsimpleDownloader { /// - startDate: Date from which the transactions are downloaded. If not date is provided, not date is sent to the API. The API falls back to 30 days ago from today. /// - completion: Result with an array of `Transactions`s or an `Transactions.TransactionsError` public func getTransactions(in account: Account, startDate: Date?, completion: @escaping (Result<[Transaction], TransactionError>) -> Void) { - guard let token = token else { + guard let token else { completion(.failure(.tokenError(.noToken))) return } diff --git a/Sources/Wealthsimple/WealthsimplePosition.swift b/Sources/Wealthsimple/WealthsimplePosition.swift index 882abb6..87a9d10 100644 --- a/Sources/Wealthsimple/WealthsimplePosition.swift +++ b/Sources/Wealthsimple/WealthsimplePosition.swift @@ -97,7 +97,7 @@ struct WealthsimplePosition: Position { URLQueryItem(name: "account_id", value: account.id), URLQueryItem(name: "limit", value: "250") ] - if let date = date { + if let date { url.queryItems?.append(URLQueryItem(name: "date", value: dateFormatter.string(from: date))) } var request = URLRequest(url: url.url!) @@ -117,8 +117,8 @@ struct WealthsimplePosition: Position { } private static func handleResponse(data: Data?, response: URLResponse?, error: Error?, completion: @escaping (Result<[Position], PositionError>) -> Void) { - guard let data = data else { - if let error = error { + guard let data else { + if let error { completion(.failure(PositionError.httpError(error: error.localizedDescription))) } else { completion(.failure(PositionError.noDataReceived)) diff --git a/Sources/Wealthsimple/WealthsimpleTransaction.swift b/Sources/Wealthsimple/WealthsimpleTransaction.swift index 921d14a..56450c2 100644 --- a/Sources/Wealthsimple/WealthsimpleTransaction.swift +++ b/Sources/Wealthsimple/WealthsimpleTransaction.swift @@ -211,8 +211,8 @@ struct WealthsimpleTransaction: Transaction { } private static func handleResponse(data: Data?, response: URLResponse?, error: Error?, completion: @escaping (Result<[Transaction], TransactionError>) -> Void) { - guard let data = data else { - if let error = error { + guard let data else { + if let error { completion(.failure(TransactionError.httpError(error: error.localizedDescription))) } else { completion(.failure(TransactionError.noDataReceived))