Skip to content

Commit

Permalink
Use shorthand optional binding
Browse files Browse the repository at this point in the history
  • Loading branch information
Nef10 authored and file-sync-app[bot] committed Dec 13, 2022
1 parent 11f82c9 commit ea7ba1e
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Sources/Wealthsimple/Token.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ struct Token {
credentialStorage: CredentialStorage,
completion: @escaping (Result<Self, TokenError>) -> 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))
Expand Down
4 changes: 2 additions & 2 deletions Sources/Wealthsimple/WealthsimpleAccount.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
8 changes: 4 additions & 4 deletions Sources/Wealthsimple/WealthsimpleDownloader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/Wealthsimple/WealthsimplePosition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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!)
Expand All @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions Sources/Wealthsimple/WealthsimpleTransaction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit ea7ba1e

Please sign in to comment.