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 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 { extension NSDecimalNumber {
func isPositive() -> Bool { func isPositive() -> Bool {

View File

@ -80,7 +80,7 @@ struct AccountTransactionsDialog: View {
private func filterTransactions(_ query: String) { private func filterTransactions(_ query: String) {
self.filteredTransactions = presenter.searchSelectedAccountTransactions(query: query) 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 { func isRequiredDataEntered() -> Bool {
return bank != nil return bank != nil
&& customerId.isEmpty == false && customerId.isNotBlank
&& password.isEmpty == false && password.isNotBlank
} }
func addAccount() { func addAccount() {

View File

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

View File

@ -72,9 +72,19 @@ struct TransferMoneyDialog: View {
Section { Section {
TextField("Remittee Name", text: $remitteeName) TextField("Remittee Name", text: $remitteeName)
.onReceive(Just(remitteeName)) { newValue in .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) TextField("Remittee IBAN", text: $remitteeIban)
.onReceive(Just(remitteeIban)) { newValue in .onReceive(Just(remitteeIban)) { newValue in
self.isValidRemitteeIbanEntered = newValue.count > 14 // TODO: implement real check if IBAN is valid self.isValidRemitteeIbanEntered = newValue.count > 14 // TODO: implement real check if IBAN is valid
@ -91,7 +101,7 @@ struct TransferMoneyDialog: View {
self.amount = filtered self.amount = filtered
} }
self.isValidAmountEntered = self.amount.isEmpty == false self.isValidAmountEntered = self.amount.isNotBlank
} }
TextField("Usage", text: $usage) TextField("Usage", text: $usage)