From af1e1551067bf5bad3dcb6084cbb7f6fbffed8e7 Mon Sep 17 00:00:00 2001 From: dankito Date: Fri, 17 Jul 2020 19:57:38 +0200 Subject: [PATCH] Made Message more generic --- .../BankingiOSApp/ui/Message.swift | 23 ++++++++++++++++++- .../ui/views/AddAccountDialog.swift | 4 ++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/Message.swift b/ui/BankingiOSApp/BankingiOSApp/ui/Message.swift index 46f2d332..c0a34926 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/Message.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/Message.swift @@ -1,8 +1,29 @@ import Foundation +import SwiftUI struct Message: Identifiable { let id = UUID() - let text: String + let title: Text + + let message: Text? + + + init(title: Text = Text(""), message: Text? = nil) { + self.title = title + self.message = message + } + + init(title: String = "", message: String? = nil) { + self.title = Text(title) + + if let text = message { + self.message = Text(text) + } + else { + self.message = nil + } + } + } diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/views/AddAccountDialog.swift b/ui/BankingiOSApp/BankingiOSApp/ui/views/AddAccountDialog.swift index 9dffbe76..71253f50 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/views/AddAccountDialog.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/views/AddAccountDialog.swift @@ -48,7 +48,7 @@ struct AddAccountDialog: View { } } .alert(item: $errorMessage) { message in - Alert(title: Text("Could not add account"), message: Text("Error message from your bank \(message.text)"), dismissButton: Alert.Button.cancel()) + Alert(title: message.title, message: message.message, dismissButton: Alert.Button.cancel())) } .navigationBarTitle(Text("Add account"), displayMode: NavigationBarItem.TitleDisplayMode.inline) } @@ -77,7 +77,7 @@ struct AddAccountDialog: View { presentation.wrappedValue.dismiss() } else { - self.errorMessage = Message(text: (response.errorToShowToUser ?? "")) + self.errorMessage = Message(title: Text("Could not add account"), message: Text("Error message from your bank \(response.errorToShowToUser ?? "")")) } } }