Reputation: 14938
I'm trying to use a Text label to output a string based on a UserDefault setting for what the translation they prefer:
Text(settings.translation? tangoArray[self.id].romaji : tangoArray[self.id].hiragana)
Is there any reason why the above line of code doesn't work, and what small modification do I need to make?
Upvotes: 1
Views: 984
Reputation: 257711
If the translation
is defined as (and hopefully changed somewhere as well)
class UserSettings: ObservableObject {
@Published var translation = UserDefaults.standard.integer(forKey: "Translation")
}
... then it has Int
type, but in Text
you must have Bool
, so it should be like
Text(settings.translation == _romaji_int_code_ ?
tangoArray[self.id].romaji : tangoArray[self.id].hiragana)
Upvotes: 2