Implemented String extensions like isBlank

This commit is contained in:
dankito 2020-07-27 13:33:00 +02:00
parent 448ce54ae9
commit f09ba7cf00
5 changed files with 46 additions and 7 deletions

View File

@ -1,6 +1,35 @@
import SwiftUI
extension String {
var isNotEmpty: Bool {
return !isEmpty
}
var isBlank: Bool {
return isEmpty || trimmingCharacters(in: .whitespaces).isEmpty
}
var isNotBlank: Bool {
return !isBlank
}
}
extension Optional where Wrapped == String {
var isNullOrEmpty: Bool {
return self?.isEmpty ?? true
}
var isNullOrBlank: Bool {
return self?.isBlank ?? true
}
}
extension NSDecimalNumber {
func isPositive() -> Bool {

View File

@ -80,7 +80,7 @@ struct AccountTransactionsDialog: View {
private func filterTransactions(_ query: String) {
self.filteredTransactions = presenter.searchSelectedAccountTransactions(query: query)
self.balanceOfFilteredTransactions = query.isEmpty ? balanceOfAllTransactions : filteredTransactions.sumAmounts()
self.balanceOfFilteredTransactions = query.isBlank ? balanceOfAllTransactions : filteredTransactions.sumAmounts()
}
}

View File

@ -63,8 +63,8 @@ struct AddAccountDialog: View {
func isRequiredDataEntered() -> Bool {
return bank != nil
&& customerId.isEmpty == false
&& password.isEmpty == false
&& customerId.isNotBlank
&& password.isNotBlank
}
func addAccount() {

View File

@ -136,7 +136,7 @@ struct EnterTanDialog: View {
Spacer()
Button(action: { self.enteringTanDone() },
label: { Text("OK") })
.disabled(self.enteredTan.isEmpty)
.disabled(self.enteredTan.isBlank)
Spacer()
}
}
@ -202,7 +202,7 @@ struct EnterTanDialog: View {
private func enteringTanDone() {
let companion = EnterTanResult.Companion()
let result = enteredTan.isEmpty ? companion.userDidNotEnterTan() : companion.userEnteredTan(enteredTan: enteredTan)
let result = enteredTan.isBlank ? companion.userDidNotEnterTan() : companion.userEnteredTan(enteredTan: enteredTan)
sendEnterTanResult(result)
}

View File

@ -72,7 +72,17 @@ struct TransferMoneyDialog: View {
Section {
TextField("Remittee Name", text: $remitteeName)
.onReceive(Just(remitteeName)) { newValue in
self.isValidRemitteeNameEntered = self.remitteeName.isEmpty == false
self.isValidRemitteeNameEntered = self.remitteeName.isNotBlank
}
if self.showRemitteeAutocompleteList {
Section {
List(self.remitteeSearchResults) { remittee in
RemitteeListItem(remittee: remittee)
.onTapGesture { self.remitteeSelected(remittee) }
}
.padding(.vertical, 12)
}
}
TextField("Remittee IBAN", text: $remitteeIban)
@ -91,7 +101,7 @@ struct TransferMoneyDialog: View {
self.amount = filtered
}
self.isValidAmountEntered = self.amount.isEmpty == false
self.isValidAmountEntered = self.amount.isNotBlank
}
TextField("Usage", text: $usage)