Remove unnecessary dictionary in favor of tuple (#1192)

The dictionary for the detected and selected language when posting is replaced
with a named tuple to include named values that are checked at compile time.
This removes a source of error while still being expressive.

Signed-off-by: Paul Schuetz <pa.schuetz@web.de>
This commit is contained in:
Paul Schuetz 2023-03-07 18:24:12 +01:00 committed by GitHub
parent b3919702e0
commit 156279faac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 6 deletions

View file

@ -170,10 +170,8 @@ public struct StatusEditorView: View {
@ViewBuilder
private var languageConfirmationDialog: some View {
if let dialogVals = viewModel.languageConfirmationDialogLanguages,
let detected = dialogVals["detected"],
if let (detected: detected, selected: selected) = viewModel.languageConfirmationDialogLanguages,
let detectedLong = Locale.current.localizedString(forLanguageCode: detected),
let selected = dialogVals["selected"],
let selectedLong = Locale.current.localizedString(forLanguageCode: selected)
{
Button("status.editor.language-select.confirmation.detected-\(detectedLong)") {

View file

@ -15,7 +15,7 @@ public class StatusEditorViewModel: NSObject, ObservableObject {
var currentAccount: Account?
var theme: Theme?
var preferences: UserPreferences?
var languageConfirmationDialogLanguages: [String: String]?
var languageConfirmationDialogLanguages: (detected: String, selected: String)?
var textView: UITextView? {
didSet {
@ -151,8 +151,7 @@ public class StatusEditorViewModel: NSObject, ObservableObject {
selectedLanguage != "",
selectedLanguage != detectedLang
{
languageConfirmationDialogLanguages = ["detected": detectedLang,
"selected": selectedLanguage]
languageConfirmationDialogLanguages = (detected: detectedLang, selected: selectedLanguage)
} else {
languageConfirmationDialogLanguages = nil
}