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 @ViewBuilder
private var languageConfirmationDialog: some View { private var languageConfirmationDialog: some View {
if let dialogVals = viewModel.languageConfirmationDialogLanguages, if let (detected: detected, selected: selected) = viewModel.languageConfirmationDialogLanguages,
let detected = dialogVals["detected"],
let detectedLong = Locale.current.localizedString(forLanguageCode: detected), let detectedLong = Locale.current.localizedString(forLanguageCode: detected),
let selected = dialogVals["selected"],
let selectedLong = Locale.current.localizedString(forLanguageCode: selected) let selectedLong = Locale.current.localizedString(forLanguageCode: selected)
{ {
Button("status.editor.language-select.confirmation.detected-\(detectedLong)") { Button("status.editor.language-select.confirmation.detected-\(detectedLong)") {

View file

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